Atomic Image widget lacks support for the sizes HTML attribute #36191
flowrange
started this conversation in
Feature Request
Replies: 1 comment
|
Hi, @flowrange, Thank you for reaching out! 🙏 ⛔ After reviewing your report we concluded this is not a bug caused by Elementor. The feature you're referring to is not yet supported.As an exception, I will migrate your issue to Feature Requests. Please, remember to follow our Contribution Guidelines. Kind regards |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Description
Hi,
I'm adding support for responsive images on some random website. This involves setting a few attributes on
imgtags. First one issrcset, which tells the browser all the available image resolutions. The other is thesizesattribute, which hints how an image behaves at specific screen sizes.I won't go into further details as this is well documented (see WordPress official Reponsive Images page).
As I have a few well-defined layouts where my images sit, I wanted to centralize those 2 attributes creation. WordPress offers 2 filters for this :
wp_calculate_image_srcset&wp_calculate_image_sizes.Unfortunately, the new atomic image widget only support the first filter,
wp_calculate_image_srcset. I need to manually add thesizeattribute in the widget settings section on each instance. This is not only tedious, but as the website's general look & feel is subject to change, I can't guarantee that I won't have to change thissizeattribute on every single one image.Fixing this issue is quite simple. The
imgtag attributes are generated usingElementor\Modules\AtomicWidgets\PropsResolver\Transformers\Image_Transformer:This should be changed according to what WordPress does in its
wp_get_attachment_imagefunction (wp-includes/media.php@1143) :See also that the
srcsetmay not be rendered if returned empty.Steps to reproduce
wp_calculate_image_srcset&wp_calculate_image_sizesin yourfunctions.phpor elsewherewp_calculate_image_sizeswasn't calledExpected behavior
wp_calculate_image_sizesto be called, and thesizesattribute to be output in the finalimgtag on the frontend.Elementor System Info
[removed by moderator]
Agreement
All reactions