- This topic has 5 replies, 3 voices, and was last updated 4 years, 5 months ago by Tom.
-
AuthorPosts
-
November 18, 2019 at 10:39 am #1066741Mathieu
Hi Tom,
I am using add_image_size() to create a custom size that won’t waste bandwith/time for anybody.
How can I hook into the code of the featured image (in the single page) so that the get_the_post_thumbnail() function uses my custom size?
Or maybe there’s a feature somewhere that I am not seeing.
Best regards,
November 18, 2019 at 10:48 am #1066748LeoStaffCustomer SupportHi there,
Is this what you are looking for?
https://docs.generatepress.com/article/adjusting-the-featured-images/#changing-the-featured-image-sizes-using-a-filter
https://codex.wordpress.org/Conditional_Tags#A_PAGE_PageLet me know π
November 18, 2019 at 11:30 am #1066775MathieuWell I was really looking into the hook. On the homepage, I do it easily a piece of code Tom gave me :
add_filter('generate_featured_image_output', function () { $isHot = false; if (isHot(get_the_id())) { $isHot = '<span class="hotpost"></span><span class="hottexte">En vedette!</span>'; } return sprintf( // WPCS: XSS ok. '<div class="post-image"> %1$s <a href="%2$s"> %3$s </a> </div>', $isHot, esc_url(get_permalink()), get_the_post_thumbnail( get_the_ID(), apply_filters('generate_page_header_default_size', '<strong>liste</strong>'), array( 'itemprop' => 'image', ) ) ); });
But I guess that *could* do the same and be much cleaner.
However, I have a few issue with using that built-in feature.
1) I have no “image_processing_queue” cron events.
2) When I am looking at the lists of available thumbnail I have inside the theme, I have nothing matching what I put in Β« Customize / Layout / Blog / Featured Image / Posts Β»
So either I have something broken or it won’t play well with the image optimization tools I use.
November 18, 2019 at 3:34 pm #1066928TomLead DeveloperLead DeveloperYou should just be able to do this:
add_filter( 'generate_page_header_default_size', function( $size ) { if ( is_page() ) { $size = 'your-custom-size'; } return $size; } );
I’m not a fan of the current image resizer, either. I have a better idea I’ll be implementing in 2020 π
November 19, 2019 at 9:27 am #1067621MathieuAhhh thank you very much Tom. I am not sure why it didn’t work yesterday as I was testing something similar.
Oh well, thanks again and have a nice day π
November 19, 2019 at 4:31 pm #1067889TomLead DeveloperLead DeveloperYou’re welcome! You too π
-
AuthorPosts
- You must be logged in to reply to this topic.