[Resolved] Hiding featured images from single post display in custom post type

Home Forums Support [Resolved] Hiding featured images from single post display in custom post type

Home Forums Support Hiding featured images from single post display in custom post type

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #298064
    Scott Pruett

    I have a custom post type (created using the Custom Post Type UI plugin), and I’d like to hide the featured image from on the single post display, but retain the featured image for use on an index of posts (using WP Show Posts). Is this do-able?

    Thanks!
    Scott

    #298070
    Scott Pruett

    For clarification, this is only for the CPT. I need to have featured images display for blog posts.

    #298121
    Leo
    Staff
    Customer Support

    Hi Scott,

    Are you able to provide a link to the page where you would like to hide the featured image?

    Thanks!

    #298135
    Scott Pruett

    Hey Leo, here’s one example.

    The image displays twice because the post is created through a form (via FormidableForms) in which an image is uploaded, displayed in a template, and also set as the featured image. The featured image will be used in an index page with WP Show Posts.

    I just need to hide the featured image, i.e. the larger one above the page content.

    Thanks,
    Scott

    #298141
    Leo
    Staff
    Customer Support

    Try Customizer > Layout > Page Header > Single Post Header Location > Hide.

    Let me know if this works.

    #298144
    Scott Pruett

    Thanks Leo, that does work!

    However, I’d like to keep the single post header for other posts (e.g., a blog), and just hide it for this custom post type. Is that possible?

    #298148
    Leo
    Staff
    Customer Support

    What’s the name of this custom post type?

    #298153
    Leo
    Staff
    Customer Support

    maybe try this CSS instead:

    .product-template-default.single .page-header-image-single {
        display: none;
    }

    Adding CSS: https://docs.generatepress.com/article/adding-css/

    Let me know.

    #298159
    Scott Pruett

    The CPT name is “product,” but I think you figured that out already. πŸ™‚

    The CSS did the trick. I’ll just use that.

    Thanks for the help!

    #298160
    Leo
    Staff
    Customer Support

    You’re welcome πŸ™‚

    #2043166
    Greg

    How do we avoid having the featured image output on the page? Ditto page title and other elements. CPTs inherit the blog layout, but I want them to be similar to Pages.

    #2043167
    Elvin
    Staff
    Customer Support

    Hi Greg,

    Can you open a new topic for this? So we don’t resurrect resolved topics for other users.

    Also, your site may have completely different structure so it’s best to have a specialized answer for it specifically.

    Thanks. πŸ˜€

    #2043179
    Greg

    Opening a new topic for hiding other features would make sense, but there are already numerous forum topics with similar sounding titles, it would really be nice to get the answers without creating more. So how, please, do we stop GP from outputting the featured image on CPT single pages?

    #2043193
    Elvin
    Staff
    Customer Support

    They may be similar sounding titles but we still need to verify things (ex. site structure, custom snippets, etc ) to know if the answer we’ll give will 100% work on the site of the user who asked. πŸ™‚

    While we can give canned answers, it’s not going to be a guaranteed correct answer for your site specifically if we don’t know the full details like site customization, and/or if you’re pertaining to the dynamic background fetched from featured image.

    That’s why we go the extra effort of verifying each site for each user. πŸ˜€

    To add further: opening a new topic lets you use the private information text field, which can be used if we have to ask for details that users don’t want to disclose on public.

    To answer your question:

    I’m not sure if the site in question is using the theme’s default post image but if it is, here’s a PHP snippet you can try:

    add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings' );
    function lh_custom_search_results_page_settings( $options ) {
        if ( is_single() && 'your_cpt_slug_here' == get_post_type() ) {
            $options['single_post_image'] = false;
        }
      
        return $options;
    }

    Then the line your_cpt_slug_here with the slug of your custom post type.

    #2043213
    Greg

    Digging through the code, I found generate_blog_single_featured_image().

    add_action( 'wp', function() {
    	if ( is_single() && 'post' != get_post_type() ) {
    		remove_action( 'generate_after_entry_header', 'generate_blog_single_featured_image' );
    		remove_action( 'generate_before_content', 'generate_blog_single_featured_image' );
    		remove_action( 'generate_after_header', 'generate_blog_single_featured_image' );
    	}
    }, 55 );
Viewing 15 posts - 1 through 15 (of 18 total)
  • The topic ‘Hiding featured images from single post display in custom post type’ is closed to new replies.