- This topic has 5 replies, 3 voices, and was last updated 4 years, 11 months ago by
Tom.
-
AuthorPosts
-
May 5, 2021 at 6:35 am #1765552
Jeffrey
Hi there!
I created a child theme of GeneratePress and trying to do the following.
1. Remove featured image on a single post
2. Add my own featured image to the single postAdding my own featured image does work quite well.
add_action( 'generate_after_entry_header', function() { if ( ! is_single() || ! has_post_thumbnail() ) { return; } $attrs = array(); if ( 'microdata' === generate_get_schema_type() ) { $attrs = array( 'itemprop' => 'image', ); } ?> <div class="featured-image youtube-link grid-container grid-parent"> <?php the_post_thumbnail( apply_filters( 'generate_page_header_default_size', 'full' ), $attrs ); ?> </div> <?php } );But removing the GeneratePress featured image does not seem to work. I checked with var_dump() if the remove_action() functions returns true, and it does. Yet when I load my page see two featured images. First one is my custom image, second is the GeneratePress image.
add_action( 'wp', function() { if ( is_single() ) { var_dump( remove_action( 'generate_after_entry_header', 'generate_post_image' ) ); var_dump( remove_action( 'generate_after_header', 'generate_featured_page_header' ) ); var_dump( remove_action( 'generate_before_content', 'generate_featured_page_header_inside_single' ) ); } } );This outputs the following at the top of the page:
bool(true) bool(true) bool(true)Hope you can help me out.
May 5, 2021 at 6:20 pm #1766514Elvin
StaffCustomer SupportHi there,
Have you tried removing the default featured image through the customizer settings?
Try unchecking “display featured image” on post tab.
https://docs.generatepress.com/article/adjusting-the-featured-images/You may also want to consider filtering the default featured image output to your preference instead of adding a new one and removing the default.
https://docs.generatepress.com/article/generate_featured_image_output/May 7, 2021 at 10:21 pm #1769833Jeffrey
Hi Elvin,
Thank you for your reply. I did check the settings at the customizer tab. If I incheck it, it does not show any image — as expected. If I check it, it shows the two featured images at the single post because of my script.
Now, I did try to use the filter first. I didn’t want to use the add_action method. But when I use the filter you redirected me to, it does not change the featured image at the single post. It only changes the featured image at the archive list, which seems a bit odd to me.
add_filter( 'generate_featured_image_output', function( $output ) { return 'FILTERED'; } );Also, I did not add any specific pages to my child time like single.php or archive.php. It just contains
– admin/
– functions.php
– style.css
– screenshot.pngI got this from your forum of one of your colleagues who made a starterpack for using a child theme with GeneratePress. I’d love to use a filter to change the featured image of my single post, if possible.
Thank you for your help!
May 8, 2021 at 10:41 am #1770596Tom
Lead DeveloperLead DeveloperHi there,
Have you tried the
generate_single_featured_image_outputfilter?add_filter( 'generate_single_featured_image_output', function( $output, $image_html ) { return sprintf( '<div class="your-custom-classes">%s</div>', $image_html ); }, 10, 2 );Using the Customizer option to disable the default featured image should work as well – it’s not aware of your custom function adding another image in, so it shouldn’t be able to prevent it from working.
May 9, 2021 at 4:25 am #1771048Jeffrey
Tom, this works just great. I was looking for this filter but I guess I wasn’t looking good enough in the docs. Thank you for your time!
May 9, 2021 at 10:11 am #1771543Tom
Lead DeveloperLead DeveloperGlad I could help! 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.