- This topic has 5 replies, 3 voices, and was last updated 6 years, 1 month ago by
Tom.
-
AuthorPosts
-
November 3, 2017 at 3:59 am #415448
Julien
Hey Tom !
This theme is such a joy to work with !
I do face an issue with featured images.On the blog page I have set featured images to be cropped like this :
Width : 1140
Height : 570
I did this setting in the GP Customize Options (Blog => Featured Images)It shows how I want it to be :
http://www.nightlycrypto.com/The problem is with the single post, it retains the original aspect ratio :
http://www.nightlycrypto.com/2017/11/03/li-europan-lingues-es-membres/For this I use, as recommended in another support ticket.
add_action( 'generate_before_content', 'tu_add_featured_image' ); function tu_add_featured_image() { if ( is_singular( 'post' ) && has_post_thumbnail() ) { the_post_thumbnail(); } }
I tried manually adding this size in the function, without luck :
add_action( 'generate_before_content', 'tu_add_featured_image' ); function tu_add_featured_image() { if ( is_singular( 'post' ) && has_post_thumbnail() ) { add_image_size('featured-single',1140,570,TRUE); the_post_thumbnail('featured-single'); } }
I have no plugins going on for now except your theme and GP Premium.
Can you help me out ?
Many thanks,
JulienNovember 3, 2017 at 8:59 am #415650Leo
StaffCustomer SupportHi there,
Do you mind GPP 1.5 premium a shot? https://generatepress.com/forums/topic/gp-premium-1-5/
It actually gives you separate re-sizing options for main blog page and single posts pages so no function needed.
Otherwise try this: https://docs.generatepress.com/article/adjusting-the-featured-images/#changing-the-featured-image-sizes-using-a-filter
Let me know π
November 3, 2017 at 9:57 am #415689Julien
Hey Leo ! Thanks for the support.
I installed GPP 1.5 (nice to see all those new features).
Unfortunately, no luck with it.
I set the sizes for both of featured images (blog and single). It doesn’t work, and I suspect it’s linked to the Page Headers tool from GPP I use. Using page headers I can only add featured images by using some code in functions.php.
I don’t get why
the_post_thumbnail();
generates something different on the front page, and on my single post page.You can see examples here :
1. With a custom page header :
http://www.nightlycrypto.com/2017/11/03/featured-image-test/2. Without a custom page header (two images, one from the functions.php , the second one from the settings) :
http://www.nightlycrypto.com/2017/11/03/gravida-iaculis-pulvinar-natoque-ornare-nonummy-lacinia-diam/Edit :
I also tried the code as a second solution without luck :
add_filter( 'generate_blog_image_attributes','tu_variable_image_sizes' ); function tu_variable_image_sizes( $atts ) { // Set up our conditional if ( is_singular( 'post' ) && has_post_thumbnail() ) : $atts[ 'width' ] = 1140; $atts[ 'height' ] = 570; $atts[ 'crop' ] = true; endif; // Return our options return $atts; }
November 3, 2017 at 8:21 pm #415927Tom
Lead DeveloperLead DeveloperIf you’re going to add a custom image size, you need to hook it into the after_setup_theme hook:
add_action( 'after_setup_theme', 'tu_add_image_sizes' ); function tu_add_image_sizes() { add_image_size( 'featured-single', 1140, 570, TRUE ); }
Then try your code:
add_action( 'generate_before_content', 'tu_add_featured_image' ); function tu_add_featured_image() { if ( is_singular( 'post' ) && has_post_thumbnail() ) { the_post_thumbnail( 'featured-single' ); } }
You may need to regenerate your thumbnails with a plugin like this: https://en-ca.wordpress.org/plugins/regenerate-thumbnails/
November 4, 2017 at 4:21 am #415998Julien
Perfecto ! It worked like a charm.
Thanks Tom and Leo.
November 4, 2017 at 9:24 am #416159Tom
Lead DeveloperLead DeveloperYou’re welcome π
-
AuthorPosts
- You must be logged in to reply to this topic.