Archived topic
Renaming The Archive Title
3 replies · Started by Jonathan on December 18, 2020
I was hoping for a cleaner way to rename the archive title by dropping, in this case, the category that the term is associated with. In this case the taxonomy is called Research Category followed by the term IHA-C. The code I'm using is this:
echo str_replace('Research Category :','', get_the_archive_title());
Which strips out the Research Category : part.
Is there a better way?
J
Hi there,
That looks good to me :)
I think you can also use the filter like this:
https://generatepress.com/forums/topic/how-to-add-a-suffix-to-the-category-archive-title/#post-1274566
Thanks for the link. I looked at the wordpress codex and used this as I wanted to remove the prefix label of the taxonomy:
function antibody_archive_title( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
}
elseif ( is_tax() ) {
$title = single_term_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'antibody_archive_title' );
Glad to hear!
No problem :)