We're merging with GenerateBlocks! Learn more here.

[Support request] Setting a custom image size for the featured post

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Setting a custom image size for the featured post

  • This topic has 16 replies, 2 voices, and was last updated 3 years ago by Tom.
Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #18462
    Carol
    Participant

    Hi,

    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.

    #18470
    Tom
    Keymaster

    Hi 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 🙂

    #18585
    Carol
    Participant

    Thanks, 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,
    Jennifer

    #18592
    Tom
    Keymaster

    That looks good – can you link me to the page possibly?

    #18594
    Carol
    Participant

    Sure! Here’s the page: http://walsh2.tbrn-aotw.com/news/

    #18623
    Tom
    Keymaster

    What 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'
    } );
    #18631
    Carol
    Participant

    Thanks! 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.

    #18656
    Carol
    Participant

    I 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!

    #18659
    Tom
    Keymaster

    At 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 🙂

    #18666
    Carol
    Participant

    It might be beyond my expertise, but I’m willing to try. 🙂

    Do you know how long it would take for the update?

    Thanks!!

    #18700
    Tom
    Keymaster

    We’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.

    #18850
    Carol
    Participant

    Hi,

    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!
    Jennifer

    #18875
    Tom
    Keymaster

    The 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

    #19000
    Carol
    Participant

    Thanks, 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 );

    #19036
    Tom
    Keymaster

    Hi there,

    Did the URL change? I’m getting a 404 now.

Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.