3

Currently my page titles are handled by WordPress, in a call to wp_head (I have add_theme_support( 'title-tag' ) in functions.php). I'd like to change the page title format for category archives - currently these look like

<Category name> Archives - <Site name>

I'd like them just to be:

<Category name> - <Site name>

Is there a way of achieving this?

0

4 Answers 4

4

If you're using the Yoast SEO plugin (which it looks like you are) then this answer might help you

If you are using yoast SEO plugin then the easiest method is to remove the archive word from "titles & metas-> Taxonomies->category"

find:

%%term_title%% Archives %%page%% %%sep%% %%sitename%% replace it with:

%%term_title%% %%page%% %%sep%% %%sitename%%

Alternatively you could try changing it using the get_the_archive_title filter as explained here

add_filter( 'get_the_archive_title', function ($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>' ;

    }

return $title;

});
1
  • Excellent, thanks for both of these - went with the Yoast solution Sep 23, 2016 at 12:35
3

You need to use the wp_title hook, try this code it should work for you :

add_filter( 'wp_title', 'my_new_category_title', 10, 2 );

function my_new_category_title($title)
{
    if (is_category() || is_archive()) {
        $title = ' - '.get_bloginfo('name').' '.$title;
    } 
    return $title;
}
0

If you only want to edit the title tag () and not what is at the top of the page you can do this:

// define the document_title_parts callback 
function filter_document_title_parts( $title ) { 
    if( is_category() ){
        $title[title] = str_replace( 'Archives', '', $title[title] );
    }
    return $title; 
}; 

// add the filter 
add_filter( 'document_title_parts', 'filter_document_title_parts', 10, 1 );
0

Also, you can change the default Category Title without using SEO plugins using a function by override the default filter single_cat_title as follow:

/**
* Add Custom Category Title
*/
add_filter( 'single_cat_title', 'custom_category_title', 10, 2 );
function custom_category_title( $title ) {
  if ( is_category() || is_archive() ) {
    $title = $title . ' Example';
  }
  return $title;
}

The output of the above code is:

Category Example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.