- This topic has 12 replies, 3 voices, and was last updated 1 year, 7 months ago by Ying.
-
AuthorPosts
-
September 13, 2022 at 10:19 am #2341942Zarar
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?
September 13, 2022 at 11:14 am #2341992YingStaffCustomer SupportHi 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.
September 13, 2022 at 12:49 pm #2342048ZararThe 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.
September 13, 2022 at 1:04 pm #2342064YingStaffCustomer SupportSo 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?
September 13, 2022 at 2:09 pm #2342089Zararhttps://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.
September 13, 2022 at 4:06 pm #2342149YingStaffCustomer SupportIs 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 );
September 13, 2022 at 7:10 pm #2342222ZararThank 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/September 13, 2022 at 7:27 pm #2342230Fernando Customer SupportHi Zarar,
generate_featured_image_output
is for archive page featured images.The solution provided by Ying is viable.
September 14, 2022 at 7:37 am #2342716ZararThank you. I suggest updating the documentation to reflect that explicitly.
September 14, 2022 at 7:39 am #2342718ZararMarking this as resolved. Thank you.
September 14, 2022 at 10:00 am #2342989YingStaffCustomer SupportGlad 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 🙂
September 14, 2022 at 1:03 pm #2343110ZararIt 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.
September 14, 2022 at 2:25 pm #2343149YingStaffCustomer SupportIf 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 theblog
page officially, but I agree we should’ve addedarchives
too as it also applies the change to archives 🙂 -
AuthorPosts
- You must be logged in to reply to this topic.