Home › Forums › Pro Support › Setting a custom image size for the featured post
Tagged: featured image, featured post
- This topic has 16 replies, 2 voices, and was last updated 3 years ago by
Tom.
-
AuthorPosts
-
August 21, 2020 at 3:05 pm #18462
Carol
ParticipantHi,
I was wondering if there is a way to set a different image size for the featured post? On the site I’m working on, the featured image can be any dimension, but then on the main index page, I want the thumbnails to look uniform and have given them a fixed size using the image height and width settings. But for the featured post, I’d like to set a different set of height and width. Is there any way to do that?
Thanks! Happy to provide more info if this isn’t clear.
August 21, 2020 at 3:29 pm #18470Tom
KeymasterHi there,
You could try something like this:
add_filter( 'wpsp_default_image_size', function( $size ) { if ( in_array( 'featured-column', get_post_class() ) ) { return 'large'; } return $size; } );
Let me know 🙂
August 25, 2020 at 10:20 am #18585Carol
ParticipantThanks, I’m having trouble getting this to work. I changed it to the full-size image and pasted it in functions.php of my child theme:
add_filter( ‘wpsp_default_image_size’, function( $size ) {
if ( in_array( ‘featured-column’, get_post_class() ) ) {
return ‘full’;
}return $size;
} );Thanks,
JenniferAugust 25, 2020 at 3:09 pm #18592Tom
KeymasterThat looks good – can you link me to the page possibly?
August 25, 2020 at 3:10 pm #18594Carol
ParticipantSure! Here’s the page: http://walsh2.tbrn-aotw.com/news/
August 26, 2020 at 2:37 pm #18623Tom
KeymasterWhat happens if you remove the width/height options you have set in the list settings right now and then do this?:
add_filter( 'wpsp_default_image_size', function( $size ) { if ( in_array( 'featured-column', get_post_class() ) ) { return 'large'; } return 'medium' } );
August 26, 2020 at 2:56 pm #18631Carol
ParticipantThanks! Alright, I tried the new code, and it looks like it’s pulling in the full size images for the other posts, instead of the medium one. We would want to pull in the thumbnail so we can crop it to exact dimensions.
August 27, 2020 at 2:40 pm #18656Carol
ParticipantI just noticed that the new code does seem to be affecting the image we have in the footer, but not the images on the main News page. Is there a way to limit its effect to just WP Show Posts images?
Thanks!
August 27, 2020 at 2:48 pm #18659Tom
KeymasterAt this time it applies to all posts, which is no good. We need to release an update that passes an extra parameter to hook so we can target one list only.
If you’re comfortable changing a bit of code, I can show you how to do that now so you don’t have to wait for the update.
Let me know 🙂
August 27, 2020 at 2:53 pm #18666Carol
ParticipantIt might be beyond my expertise, but I’m willing to try. 🙂
Do you know how long it would take for the update?
Thanks!!
August 28, 2020 at 2:27 pm #18700Tom
KeymasterWe’re working on it right now, hopefully soon.
For now, you can find this line: https://github.com/tomusborne/wp-show-posts/blob/master/inc/functions.php#L193
And replace it with this:
the_post_thumbnail( apply_filters( 'wpsp_default_image_size', 'full', $settings ), array( 'itemprop' => 'image' ) );
Then your filter from up above would look like this:
add_filter( 'wpsp_default_image_size', function( $size, $settings ) { if ( 123 === $settings['list_id'] && in_array( 'featured-column', get_post_class() ) ) { return 'large'; } return $size; }, 10, 2 );
You just need to update
123
to the list ID of the list you’re targeting.September 1, 2020 at 3:17 pm #18850Carol
ParticipantHi,
I’m still having trouble getting it to work, but I’m wondering if I’m doing it wrong.
I updated function.php, line 193 in this file: /wp-content/plugins/wp-show-posts/inc/function.php
I then added the filter to this file: /wp-content/themes/generatepress_child/function.php
I changed the filter ID to match the list ID.
I changed line 3 to:return ‘full’ (because of space issues, we don’t have our WP create any large images.)
Then in WP Show Posts settings, I set the image size to 400px W x 400 px H — because we want them to be square.
I’m seeing the featured image as a square again and wondering where I went wrong.
Thanks!
JenniferSeptember 2, 2020 at 3:07 pm #18875Tom
KeymasterThe image settings in the list will overwrite the filter you’ve used, unfortunately.
If you want to make them square, you’ll want to add new image sizes: https://wpshowposts.com/support/topic/show-posts-images-not-working/#post-8324
September 4, 2020 at 2:59 pm #19000Carol
ParticipantThanks, Tom. It’s getting close! I have all the images pulling in a square image that is the custom image I made. Unfortunately, the featured post is also pulling the custom image instead of the “Full” image. I confirmed I did add this to function.php in my child theme:
add_filter( ‘wpsp_default_image_size’, function( $size, $settings ) {
if ( 641 === $settings[‘list_id’] && in_array( ‘featured-column’, get_post_class() ) ) {
return ‘full’;
}return $size;
}, 10, 2 );September 5, 2020 at 2:09 pm #19036Tom
KeymasterHi there,
Did the URL change? I’m getting a 404 now.
-
AuthorPosts
- You must be logged in to reply to this topic.