Description
Issue Overview
The filter_post_thumbnail_sizes_attr() function in inc/Image_sizes/Component.php looks like it's blocking the WordPress image functions' ability to set a custom attribute and always comes out at '100vw'
Steps to Reproduce
- Use any native WP function which outputs an image tag
- In the $attr parameter pass 'sizes' into the array with any value
Expected Behavior
'sizes' attribute on the image tag on the frontend should match the one passed to the $attr array
e.g.
wp_get_attachment_image($id, 'thumbnail', false, array('sizes' => '(max-width: 768px) 100vw, 20vw'))
should produce
<img width="250" height="250" src="http://mysite.com/wp-content/uploads/2021/04/test-1-250x250.png" class="attachment-thumbnail size-thumbnail" alt="" loading="lazy" sizes="(max-width: 768px) 100vw, 20vw" srcset="http://mysite.com/wp-content/uploads/2021/04/test-1-250x250.png 250w, http://mysite.com/wp-content/uploads/2021/04/test-1-360x360.png 360w, http://mysite.com/wp-content/uploads/2021/04/test-1-500x500.png 500w">
Current Behavior
'sizes' attribute on the image is always '100vw'
<img width="250" height="250" src="http://mysite.com/wp-content/uploads/2021/04/test-1-250x250.png" class="attachment-thumbnail size-thumbnail" alt="" loading="lazy" sizes="100vw" srcset="http://mysite.com/wp-content/uploads/2021/04/test-1-250x250.png 250w, http://mysite.com/wp-content/uploads/2021/04/test-1-360x360.png 360w, http://mysite.com/wp-content/uploads/2021/04/test-1-500x500.png 500w">
Possible Solution
Change 'inc/Image_Sizes/Component.php:85' from
$attr['sizes'] = '100vw';
to
if( !$attr['sizes']){ $attr['sizes'] = '100vw'; }
This seemed to work for me, may need more extensive testing