Site logo

Archived topic

SCRSET confusion

6 replies · Started by George on July 14, 2021

Viewing posts 1–7 of 7

I have the three default image sizes set in the Media settings as the following:

Thumbnail size: 150 X150
Medium size: 450 X 300
Large size: 1000 X 667

In addition, I've added an extra dimension that I would like to have for my featured image archives:

add_action( 'init', function() {
    add_image_size( 'archive_featured-image', 387, 258, false );
} );

387px is the size that I've calculated the featured image to be for the archives on desktop, similar for other devices.

I have also set up a block content template element type to display on my archives and have set the image size to be archive_featured-image.

What I would expect to see when visiting the archive is for the correct SCRSET to be selected which it doesn't. As far as I understand, setting archive_featured-image for the featured image in the content template block element will select that scrset size or smaller:
https://generatepress.com/forums/topic/how-do-i-load-srcset-featured-image-for-mobile-and-desktop/#post-1661600

Instead, I am getting a size of 768X512px and I have no idea where that size is coming from. In sizes less than 294px device-width, I get the 450X300px size image. And in size less than 209px device-width, I get the 387X258px size image. I can see those images served from the Network tab in the Chrome inspector.

Of course, I have regenerated all thumbnails.

Can you help clear the confusion?

Hi George,

the 768x size image is the medium_large attachment size that WP generates.
The browser selects from src-set sizes the best fit image for the purpose which considers the screens pixel density.
See here when i set the DPR of the device to 1 it grabs the smallest image:

https://www.screencast.com/t/5C3w89bVU

I thought, setting an image size in the post template would take that size or anything smaller as described in the post that I attached earlier in which you comment. Is that not the case?

Hi David, Is there any news on this? Should I assume that the size set in the dynamic image is not being taken into consideration?

Hi George - sorry i though i replied to your previous reply, my loggin must have expired on submit.
Thats correct, unless we force the maxsizes option for it then WP will load the larger sizes. Its something we're looking at.

Ok, yes, I see. It actually grabs the width and height attributes of what's set for the image but displays the higher SCRSET one! I think for the time being I will restrict max SCRSET width as you explain here.

Yep - thats the function :)

This archived topic is closed to new replies.