The get_the_archive_title WordPress PHP filter allows you to modify the archive title that is displayed on your website.
Usage
add_filter( 'get_the_archive_title', 'your_function_name', 10, 3 );
function your_function_name( $title, $original_title, $prefix ) {
// your custom code here
return $title;
}
Parameters
$title(string) – Archive title to be displayed.$original_title(string) – Archive title without prefix.$prefix(string) – Archive title prefix.
More information
See WordPress Developer Resources: get_the_archive_title
Examples
Remove prefix from the archive title
This code removes the default prefix from the archive title.
add_filter( 'get_the_archive_title', 'remove_archive_title_prefix', 10, 3 );
function remove_archive_title_prefix( $title, $original_title, $prefix ) {
return $original_title;
}
Add a custom prefix to the archive title
This code adds a custom prefix to the archive title.
add_filter( 'get_the_archive_title', 'add_custom_archive_title_prefix', 10, 3 );
function add_custom_archive_title_prefix( $title, $original_title, $prefix ) {
$custom_prefix = 'Browse: ';
return $custom_prefix . $original_title;
}
Change prefix for category archives
This code changes the prefix for category archive titles.
add_filter( 'get_the_archive_title', 'change_category_archive_title_prefix', 10, 3 );
function change_category_archive_title_prefix( $title, $original_title, $prefix ) {
if ( is_category() ) {
$new_prefix = 'Articles in: ';
return $new_prefix . $original_title;
}
return $title;
}
Change prefix for tag archives
This code changes the prefix for tag archive titles.
add_filter( 'get_the_archive_title', 'change_tag_archive_title_prefix', 10, 3 );
function change_tag_archive_title_prefix( $title, $original_title, $prefix ) {
if ( is_tag() ) {
$new_prefix = 'Posts tagged: ';
return $new_prefix . $original_title;
}
return $title;
}
Change prefix for author archives
This code changes the prefix for author archive titles.
add_filter( 'get_the_archive_title', 'change_author_archive_title_prefix', 10, 3 );
function change_author_archive_title_prefix( $title, $original_title, $prefix ) {
if ( is_author() ) {
$new_prefix = 'Written by: ';
return $new_prefix . $original_title;
}
return $title;
}