[Resolved] Hide featured image under some conditions

Home Forums Support [Resolved] Hide featured image under some conditions

Home Forums Support Hide featured image under some conditions

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1564515
    webintas

    Hi there,

    In some specific cases I want to remove the featured image. I have tried the code below but that does not work. How to do it?

    add_action( ‘wp’,’generate_remove_featured image’ );
    function generate_remove_featured () {
    if (is_single(1256)){
    remove_action(‘generate_before_content’,’generate_featured_page_header_inside_single’, 10);
    }
    }

    #1564517
    Leo
    Staff
    Customer Support

    Hi there,

    In some specific cases I want to remove the featured image.

    Can you let me know what those cases are?

    #1564668
    webintas

    It depend on whether a custom field is filled out the the backend. I offer the bloggers an opportunity to insert a YouTube video instead of the featured image. If they do, I need to remove the featured image from single.

    #1564867
    Leo
    Staff
    Customer Support
    #1565166
    webintas

    We are on the right track with the disable elements option. But is it possible to do it from the PHP code?

    #1566069
    Leo
    Staff
    Customer Support

    Your function names need to match:
    https://www.screencast.com/t/9DsxqVtUvw9Z

    And the syntax for is_single need to be corrected as well:
    https://codex.wordpress.org/Conditional_Tags#A_Single_Post_Page

    #1566328
    webintas

    Wauw.. How could I miss that.

    However, it did not help. I have tried to clean up and keep it simple:

    add_action('wp','generate_remove_featured');
    function generate_remove_featured () {
    	remove_action('generate_before_content','generate_featured_page_header_inside_single', 10);
    }

    That does not work either.

    #1566403
    Leo
    Staff
    Customer Support

    Is the Blog module activated?

    If so try this filter instead:
    https://docs.generatepress.com/article/option_generate_blog_settings/#options-%E2%80%98single_post_image%E2%80%99

    Example:

    add_filter( 'option_generate_blog_settings', function( $options ) {
        if ( is_single( '17' )  ) {
            $options['single_post_image'] = false;
        }
    
        return $options;
    } );
    #1567713
    webintas

    Thanks ! That helped ๐Ÿ™‚

    #1567728
    Leo
    Staff
    Customer Support

    No problem ๐Ÿ™‚

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