[Support request] Change Post Title Colour by Category

Home Forums Support [Support request] Change Post Title Colour by Category

Home Forums Support Change Post Title Colour by Category

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2236585
    Shaun

    Hi
    I want to change the title colour of posts with a particular category (category = deals. I want to change it for both single posts and in their WP Show Posts listing.
    For example, see the Sample deal at the bottom of the site I have added to private information.
    I found the following advice from Leo, which may work for the WP Show Posts list view, but I am unsure.
    Note, I only need to change the colour of the deals category of posts. All other post categories use the default settings.
    Thanks
    Shaun

    #2237037
    David
    Staff
    Customer Support

    Hi there,

    1. you will need to add this PHP Snippet to your site:

    add_filter( 'body_class', function( $classes ) {
        if ( is_single() ) {
            global $post;
    
            foreach( ( get_the_category( $post->ID ) ) as $category ) {
                $classes[] = 'category-' . $category->category_nicename;
            }
        }
    
        return $classes;
    } );

    This will add the category-term class to the body element of the single post.

    2. Then you can use this CSS:

    .category-deals h1,
    .category-deals .wp-show-posts-entry-title a {
       color: #f00 !important;
    }

    That will target the single post H1 and the WPSP Title link.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.