Filter

How to Customise the WordPress Archive Title

Sometimes we want to customise the WordPress Archive title which WordPress creates automatically for us.

For example, we may want to get rid of the “Category:” prefix in the Archive title or we may want to completely change the entire title – perhaps instead of “Archives: House” that WordPress would produce for a Post Type called House, we may want to display “All Our Houses” or anything alike.

There is a filter to achieve that in the WordPress API: get_the_archive_title

Below is an example code snippet which would be placed for example in your themes functions.php file. It will change the Archive Title of a Post Type with slug my-post-type from Archives: My Post Type to “My Own Stuff!

function my_theme_archive_title( $title ) {

     if ( is_post_type_archive(['my-post-type']) ) {
         $title = 'My Own Stuff!';
     } 

     return $title;
 }
 add_filter( 'get_the_archive_title', 'my_theme_archive_title' );

Note that the linked WordPress Document above (here again) and also StackOverflow have more complete and dynamic examples of how to use this filter.

If you need further help with this sort of Customisations don’t hesitate to get in touch! As usual, at TukuToi you will Pay What You Can and Get What You Need