Site logo

Archived topic

Style second part of the category archive heading

3 replies · Started by George on September 18, 2018

Viewing posts 1–4 of 4

I was wondering if there is a function that I could use to split the category archive heading with spans so I could style the second part of the heading.

For example, Category: Common Queries. I would like to style the Common Queries with a different color. Is there a way to do that without creating a modifying the archive template (and thus creating a child theme)?

Hi there,

You might be able to do something like this:

add_filter( 'get_the_archive_title', function( $title ) {
    if ( is_category() ) {
        $title = 'Category: <span class="cat-name">' . single_tag_title( '', false ) . '</span>';
    }

    return $title;
} );

That was too easy Tom, thanks! Mine was a custom post archive category so I used is_tax() conditional instead:

add_filter( 'get_the_archive_title', function( $title ) {
    if ( is_tax('epkb_post_type_1_category') ) {
        $title = 'Category: <span class="cat-name">' . single_tag_title( '', false ) . '</span>';
    }
    return $title;
} );

Thanks again!

You're welcome :)

This archived topic is closed to new replies.