To remove the “Archives” label from archive pages in WordPress, you can use the get_the_archive_title
filter hook. This hook allows you to modify the archive title before it is displayed on the page.
Here’s an example code snippet that removes the “Archives” label from archive pages:
function wpsnippets_remove_archive_label( $title ) {
if ( is_archive() && ! is_post_type_archive() ) {
$title = single_cat_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'wpsnippets_remove_archive_label' );
This code snippet checks if the current page is an archive page (using the is_archive()
function) and not a post type archive. If it is, it replaces the archive title with the category title (using the single_cat_title()
function). The modified title is then returned.
By adding this code to your theme’s functions.php
file or a custom plugin, the “Archives” label will be removed from archive pages, and instead, the category title will be displayed.
This code snippet can be useful when you want to customize the display of archive pages and remove the default “Archives” label to provide a cleaner and more specific title for your visitors.
Examples
Example #1: Removing the “Archives” label using a filter hook
This example demonstrates how to remove the “Archives” label from archive pages by using the get_the_archive_title
filter hook.
function wpsnippets_remove_archives_label( $title ) {
if ( is_archive() ) {
$title = str_replace( 'Archives: ', '', $title );
}
return $title;
}
add_filter( 'get_the_archive_title', 'wpsnippets_remove_archives_label' );
In this code example, we define a custom function wpsnippets_remove_archives_label
that checks if the current page is an archive page using the is_archive()
conditional tag. If it is, we remove the “Archives: ” prefix from the archive title using str_replace()
. Finally, we hook this function to the get_the_archive_title
filter using add_filter()
.
Example #2: Removing the “Archives” label using a template override
This example demonstrates an alternative approach to remove the “Archives” label by overriding the archive template.
function wpsnippets_custom_archive_title( $title ) {
if ( is_archive() ) {
$title = single_cat_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'wpsnippets_custom_archive_title' );
In this code example, we create a custom function wpsnippets_custom_archive_title
that checks if the current page is an archive page using is_archive()
. If it is, we replace the archive title with the category title using single_cat_title()
. Finally, we hook this function to the get_the_archive_title
filter.
Example #3: Removing the “Archives” label using CSS
This example demonstrates how to hide the “Archives” label using CSS.
.archive-title {
display: none;
}
In this code example, we target the HTML element that contains the “Archives” label using its class .archive-title
and set its display
property to none
. This effectively hides the label from the page.