Archived topic
generate_featured_image_output not working
12 replies · Started by Zarar on September 13, 2022
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?
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.
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.
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?
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.
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 );
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/
Hi Zarar,
generate_featured_image_output is for archive page featured images.
The solution provided by Ying is viable.
Thank you. I suggest updating the documentation to reflect that explicitly.
Marking this as resolved. Thank you.
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 :)
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.
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 :)