Implement apply_filters( ‘get_the_archive_title’) to Remove WordPress Category, Tag Page Title Prefix – WordPress Tutorial

By | June 20, 2020

When you are creating a wordpress theme, you may find there exists a prefix in the title of wordpress category page, tag page and archive page. In this tutorial, we will introduce how to remove this prefix.

Preliminary

As to wordpress, the prefix of wordpress category, tag and archive page title is:

Page Title Prefix
Category Category:
Tag Tag:
Archive Archives:

Here is an example:

Implement apply_filters( 'get_the_archive_title') to Remove WordPress Category, Tag Page Title Prefix - WordPress Tutorial

How to remove prefix?

We can apply_filters( ‘get_the_archive_title’) to do it.

Open your theme functions.php and add code below.

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 = get_the_author();
    } elseif ( is_post_type_archive() ) {
        $title = post_type_archive_title( '', false );
    } elseif ( is_tax() ) {
        $title = single_term_title( '', false );
    }
 
    return $title;
}
 add_filter( 'get_the_archive_title', 'my_theme_archive_title' );

Save it, then you will find the prefix disappear.

Leave a Reply

Your email address will not be published. Required fields are marked *