New Archive Page Title Filters in WP 5.5

WordPress 5.5 adds a couple new filters that should be useful to adjust the page title displayed in the archive.php template. See this article for more details.

The first is a filter named get_the_archive_title_prefix which can be used to change or remove the prefix returned when using the function get_the_archive_title to write out the page title in the archive.php template. Examples:

To replace the archive title prefix with another text, use:

function mytheme_archive_title_prefix( $prefix ){
    $prefix = __( 'Currently viewing archives for:', 'my-theme' ); 
    return $prefix;
}
add_filter( 'get_the_archive_title_prefix', 'mytheme_archive_title_prefix' );

To completely remove the archive title prefix, use:

add_filter( 'get_the_archive_title_prefix', '__return_empty_string' );

get_the_archive_title filter (not function) appears to also be modified to add 2 more parameters in WP 5.5:

  • $title: Archive title to be displayed
  • $original_title: Archive title without prefix (new)
  • $prefix: Archive title prefix (new)

Example using this hook with 2 new parameters:

function mytheme_get_the_archive_title( $title, $original_title, $prefix ) {
    $prefix = '<span class="archive-prefix">' . __( 'Currently viewing archives for:', 'my-theme' ) . '</span>';
    $title  = '<span class="archive-title">' . $original_title . '</span>';
    return $prefix . $title;
}
add_filter( 'get_the_archive_title', 'mytheme_get_the_archive_title', 10, 3 );
Do NOT follow this link or you will be banned from the site!