Site logo

Archived topic

Renaming The Archive Title

3 replies · Started by Jonathan on December 18, 2020

Viewing posts 1–4 of 4

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

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 :)

This archived topic is closed to new replies.