Site logo

Archived topic

Featured images for home page & post page

3 replies · Started by Kathy on September 1, 2022

Viewing posts 1–4 of 4

Hi! I have my newest blog posts fed into my homepage and I have warnings on them all that the image is too large for the container.

But if I resize them for the home page containers, then they show up too small to be a featured image on the post page.

Is there way to have a posts featured image sized for the home page, as well as the post page.

http://craftychica.com

Thanks for any help!

Hi Kathy,

May I first ask where you’re getting the warnings?

Smush Pro! They put a little yellow frame around my images that need attention then it tells the size they are and the size of the container. And it says I should resize them to fit in the container.

I see.

Can you try resizing them using this filter and see if that works?: https://docs.generatepress.com/article/adjusting-the-featured-images/#changing-the-featured-image-sizes-using-a-filter

For instance:

add_filter( 'generate_blog_image_attributes', function( $atts ) {
    if ( is_home() ) {
        $atts[ 'width' ] = 300;
        $atts[ 'height' ] = 300;
        $atts[ 'crop' ] = true;
    }

    // Return our options
    return $atts;
} );

Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets

This archived topic is closed to new replies.