Archived topic
Customise Archive pages?
4 replies · Started by Kev on May 14, 2021
Hi folks,
I'm trying to customise my archives, but I can't seem to do it. What I'm trying to do is remove the name of the Category in the archive and replace it with a different title.
So, for example, if I go to /category/writing to look at my "writing" archive, the title at the top just says "Writing", but I'd like to replace that with "Writing Archives" and maybe a paragraph of text.
I tried a layout element, but when I choose to disable "Content Title" the title of the page remains. I know I'll be able to add the paragraph with a block element, but I can't seem to figure out how to replace the page title?
Thanks!
Hi there,
you can use a PHP Snippet to filter the archive title:
add_filter( 'get_the_archive_title', function ( $title ) {
$title_postfix = ' Archives';
$title .= $title_postfix;
return $title;
},50);
Just update the $title_postfix value to what you want displayed after the Title.
For the paragraph of text - if you add a Description to the Category Term then it will be displayed below the title by default.
Hi David,
Thanks for this, but the PHP snippet didn't quite work:
Before the change it would say "Archive: Writing"
After the change it says "Archive: Writing Archives"
How do I get rid of "Archive:"?
This is now resolve. I managed to fix the problem myself by adding the following to my functions.php:
// Remove "Archive:", "Category:" etc.
add_filter( 'get_the_archive_title', function ($title) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
} elseif ( is_author() ) {
$title = '<span class="vcard">' . get_the_author() . '</span>' ;
} elseif ( is_tax() ) { //for custom post types
$title = sprintf( __( '%1$s' ), single_term_title( '', false ) );
} elseif (is_post_type_archive()) {
$title = post_type_archive_title( '', false );
}
return $title;
});
This will remove "Archive:", "Category:", "Tag:" etc. from all archive pages.
Glad to hear you found the solution