Archived topic
srcset and sizes attributes
3 replies · Started by Carlos on February 19, 2021
The theme generatepress is currently already managing correctly
srcset and sizes attributes?
example:
The original image (3200px wide) is not in the srcset attribute. This is because by default, wordpress applies a 1600px limit to prevent themes that were not designed to work with adaptive images from loading huge images.
This limit can be removed using this function
apply_filters( 'max_srcset_image_width', int $max_width, int[] $size_array )
The sizes attribute is very simplistic. It means that if the screen size is larger than the image, the width of the image must not exceed the defined size (300px or 525px). If the screen is smaller than the width of the image, the image must take the full width of the screen. We will say that this rule is well suited for designs that are not too complicated with images that take the full width of the screen up to a certain size. But for more advanced responsive sites, the sizes attribute must be modified so that the most suitable image is loaded in all cases!
But since I am not a developer and what if my images with the generatepress theme do not respond ... what can I do?
Hi there,
thats correct WP's method of adding sizes for your src-set attributes makes the assumption the image will fill the width of the viewport.
If you feel the need to adapt that behaviour, you can use this filter: wp_calculate_image_sizes
Which this article explains in detail:
https://www.malthemilthers.com/responsive-images-and-how-to-implement-them-in-wordpress/
Thanks
You're welcome