[Resolved] Style second part of the category archive heading

Home Forums Support [Resolved] Style second part of the category archive heading

Home Forums Support Style second part of the category archive heading

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #680120
    George

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

    GeneratePress 2.1.4
    GP Premium 1.7.2
    #680793
    Tom
    Lead Developer
    Lead Developer

    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;
    } );
    #680948
    George

    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!

    #681296
    Tom
    Lead Developer
    Lead Developer
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.