[Resolved] Hide featured image on single post page for specific category

Home Forums Support [Resolved] Hide featured image on single post page for specific category

Home Forums Support Hide featured image on single post page for specific category

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #445903
    Denise

    Hello GP Friends,

    How can I hide the featured image on single post pages for a specific category? I’m using GP Pro and have a child theme.

    Many thanks for the fabulous theme!

    Denise

    #445922
    Leo
    Staff
    Customer Support

    Hi there,

    We can use some CSS for that. Can you link me to one of those single posts?

    Thanks!

    #445927
    Denise

    Thanks Leo. I have responded by email to send you the links.

    Denise

    #445946
    Leo
    Staff
    Customer Support

    Ok little more complicated than I thought.

    First you need this snippet to add the category class in single post:
    https://generatepress.com/forums/topic/change-header-background-for-category-or-pages/#post-108374

    Then this CSS should work:

    .category-video.single .featured-image {
        display: none;
    }
    #445954
    Denise

    Hi Leo,

    I added the CSS to the child theme style sheet, but it didn’t change anything. Could we do this with a function, hook or filter?

    By the way, I’m a database programmer, so I’m pretty comfortable with the code side of things if we need to go there.

    Denise

    #445957
    Denise

    I think the selecter that controls this image is:
    .post-image-aligned-left .inside-article .featured-image

    #445958
    Leo
    Staff
    Customer Support

    Did you add Tom’s php snippet?

    #445968
    Tom
    Lead Developer
    Lead Developer

    You could try this:

    add_filter( 'generate_single_featured_image_output', 'tu_remove_single_post_image' );
    function tu_remove_single_post_image( $output ) {
        if ( in_category( 'video' ) ) {
            return '';
        }
    
        return $output;
    }
    #446283
    Denise

    Hi Leo and Tom,

    Leo, you are correct.I forgot to add the php code snippet. Once I did, the CSS display none method worked great. Then I commented that out and tried Tom’s filter, that didn’t need the CSS. That also worked. I will use the filter method.

    Thanks a million for your continued great work. I LOVE the GP theme. You’ve made this web project a joy to work on. =)

    #446306
    Leo
    Staff
    Customer Support

    Tom’s method is definitely better 🙂

    Glad we could help!

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