Black Friday Sale! Get $20 off GP Premium, $40 off our new Lifetime license, and 45% off license renewals/extensions! Learn more

[Resolved] Hide featured image in single CPT

Home Forums Support Hide featured image in single CPT

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #447887
    Igor

    I want to hide featured image just for a CPT. I want to still show featured images in blog single posts or other CPTs, but there is no way to hide it using code. I know I could use CSS but I don’t want the code being loaded.

    I’ve tried this but doesn’t work:

    add_action( 'wp', 'tu_remove_featured_images', 15 );
    function tu_remove_featured_images() {
        if ( is_singular( 'proyecto' ) ){
            remove_action( 'generate_after_header','generate_page_header', 10 );
        }
    }
    

    I’m using last version or GP and GP Premium. This worked some weeks ago. Not sure before which upgrade.

    Thanks

    GeneratePress 2.0
    GP Premium 1.5.6
    #448152
    Leo
    Staff
    Customer Support

    Hi there,

    Can you try:

    add_action( 'wp', 'lh_remove_single_cpt_page_header' );
    function lh_remove_single_cpt_page_header() {
        if ( 'proyecto' == get_post_type() ) {
            remove_action( 'generate_after_header','generate_page_header' );
        }
    }
    #448341
    Igor

    I tried before, including other combinations. It doesn’t work. There was a mistake in your code, anyway, the function name should be tu_remove_single_cpt_page_header instead of lh_remove_single_cpt_page_header. I’m placing it in my child theme’s functions.php code. Any solution? πŸ™

    #448880
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this:

    add_filter( 'option_generate_blog_settings', 'tu_hide_featured_image_cpt' );
    function tu_hide_featured_image_cpt( $options ) {
        if ( 'proyecto' == get_post_type() ) {
            $options['single_post_image'] = false;
        }
    
        return $options;
    }
    #449186
    Igor

    Now it works! thanks. The question is: Is this an isolated situation? I mean, the first solution explained does usually work? I ask because I have other websites using GP and maybe I can find same situation after upgrading GP.

    #449487
    Tom
    Lead Developer
    Lead Developer

    The first solution is for the Page Header, which was separated completely from static featured images in GPP 1.5.

    A “Page Header” now requires the use of the content field in the Page Header.

    #449621
    Igor

    Maybe would be nice idea if this is explained in Docs! πŸ˜‰ Thanks!!

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