How to remove “Archive:”, “Category:” etc. pre-title inserts in Archive Titles
Updated on July 22, 2019
In Oxygen when you go to Insert Data > Archive Title in a Template for an archive page, it is going to dynamically fetch and show the current archive’s title preceded by a label that reads “Archive:” or “Category:” etc. depending on the context.
Ex.: Category: Uncategorized
If you want to remove these pre-title insert labels, follow these steps:
Step 1
Install and activate Code Snippets plugin.
Step 2
Go to Snippets > Add New.
Title: Get rid of the “Category:”, “Tag:”, “Author:”, “Archives:” and “Other taxonomy name:” in the archive title
Code:
add_filter( 'get_the_archive_title', 'my_theme_archive_title' );
/**
* Remove archive labels.
*
* @param string $title Current archive title to be displayed.
* @return string Modified archive title to be displayed.
*/
function my_theme_archive_title( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
} elseif ( is_author() ) {
$title = '<span class="vcard">' . get_the_author() . '</span>';
} elseif ( is_post_type_archive() ) {
$title = post_type_archive_title( '', false );
} elseif ( is_tax() ) {
$title = single_term_title( '', false );
}
return $title;
}
Source: https://developer.wordpress.org/reference/functions/get_the_archive_title/#comment-1807
Update on July 21, 2019
If you wish to show the title of the Page set as Posts page (at Settings > Reading) automatically as the title on the Posts page, change the above code to
add_filter( 'get_the_archive_title', 'my_theme_archive_title' );
/**
* Remove archive labels.
*
* @param string $title Current archive title to be displayed.
* @return string Modified archive title to be displayed.
*/
function my_theme_archive_title( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
} elseif ( is_author() ) {
$title = '<span class="vcard">' . get_the_author() . '</span>';
} elseif ( is_post_type_archive() ) {
$title = post_type_archive_title( '', false );
} elseif ( is_tax() ) {
$title = single_term_title( '', false );
} elseif ( is_home() ) {
$title = single_post_title( '', false );
}
return $title;
}
Reference: https://cameronjonesweb.com.au/blog/how-to-add-the-blog-page-content-to-blog-post-listings/