[Resolved] generate_featured_image_output not working

Home Forums Support [Resolved] generate_featured_image_output not working

Home Forums Support generate_featured_image_output not working

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #2341942
    Zarar

    This filter doesn’t seem to be kicking in:

    This should result in no featured images being displayed anywhere, but they’re all still showing up.

    add_filter( 'generate_featured_image_output', function( $output ) {
    	return "";
    }, 11, 1 );

    What could I be doing wrong?

    #2341992
    Ying
    Staff
    Customer Support

    Hi there,

    You can disable the featured image at customizer > layout > blog > featured image.

    I don’t see the point to use this filter.

    Let me know if there’s a specific reason.

    #2342048
    Zarar

    The point is that I don’t want to display the featured image in very specific cases. For example when the post is tagged with a particular item and a YouTube video exists in the post. Only in those cases do I not want to display a featured image on the page.

    #2342064
    Ying
    Staff
    Customer Support

    So you are going to add some condition to the filter so it only removes the featured image for those cases?

    Can you show me an example?

    #2342089
    Zarar

    https://www.raptorsrepublic.com/2022/09/13/drafting-our-top-nba-dpoy-award-candidates-rap-up/

    In this case I don’t want a featured image displayed since it is redundant as there’s already a YouTube thumbnail with the same image on the screen.

    #2342149
    Ying
    Staff
    Customer Support

    Is the only difference between this post and other posts the Youtube video?

    If so, try this snippet:

    add_action('wp',function() {
    	 $post_content = get_the_content(get_the_id());
             if ( strpos( $post_content, 'wp-block-embed-youtube' ) && is_single() ) {
                 remove_action( 'generate_after_entry_header', 'generate_blog_single_featured_image' );
             }
    }, 100 );
    #2342222
    Zarar

    Thank you for that solution. I am OK using it but it seems a bit of a hack. Is there a reason why generate_featured_image_output doesn’t work as advertised here? https://docs.generatepress.com/article/generate_featured_image_output/

    #2342230
    Fernando
    Customer Support

    Hi Zarar,

    generate_featured_image_output is for archive page featured images.

    The solution provided by Ying is viable.

    #2342716
    Zarar

    Thank you. I suggest updating the documentation to reflect that explicitly.

    #2342718
    Zarar

    Marking this as resolved. Thank you.

    #2342989
    Ying
    Staff
    Customer Support

    Glad it works 🙂

    Thank you. I suggest updating the documentation to reflect that explicitly.

    In the documentation of generate_featured_image_output, we indicated that it alter the HTML of the featured image on the posts/blog page, this doesn’t include the featured image on single post page.

    Hope that’s clear 🙂

    #2343110
    Zarar

    It is not. As Fernando said, saying “archive pages” is more clear.

    When I read that I thought “posts” page meant pages where a post is displayed.

    #2343149
    Ying
    Staff
    Customer Support

    If you go to settings > reading, you will see the Posts page option under Your homepage displays section.

    In WP, posts page is the same as the blogpage officially, but I agree we should’ve added archives too as it also applies the change to archives 🙂

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