I'm noticing a difference (bug?) in how WP is rendering srcset images now.
If I register my image sizes with
add_image_size('single_featured_image', 1280, 9999, false);
add_image_size('single_featured_image_2X', 2560, 9999, false);
and confirm the files generated
test-image-1280x720.jpg test-image-2560x1440.jpg
and then attempt to render them with
echo wp_get_attachment_image(
get_post_thumbnail_id(),
'single_featured_image',
false,
[
'class' => 'object-cover object-center w-full h-full'
]
);
HTML rendered is
<img width="1280" height="720" src="http://wauble.lndo.site/wp-content/uploads/2023/07/test-image-2-1280x720.jpg" class="object-cover object-center w-full h-full" alt="" decoding="async" loading="lazy" srcset="http://wauble.lndo.site/wp-content/uploads/2023/07/test-image-2-1280x720.jpg 1280w, http://wauble.lndo.site/wp-content/uploads/2023/07/test-image-2-300x169.jpg 300w, http://wauble.lndo.site/wp-content/uploads/2023/07/test-image-2-1024x576.jpg 1024w, http://wauble.lndo.site/wp-content/uploads/2023/07/test-image-2-768x432.jpg 768w, http://wauble.lndo.site/wp-content/uploads/2023/07/test-image-2-1536x864.jpg 1536w, http://wauble.lndo.site/wp-content/uploads/2023/07/test-image-2-2048x1152.jpg 2048w, http://wauble.lndo.site/wp-content/uploads/2023/07/test-image-2-18x10.jpg 18w" sizes="(max-width: 1280px) 100vw, 1280px">
Notice 2560x is not included in the srcset values.
I'm assuming there is some proportion matching going on. What's strange is I used to use this technique all the time and always seemed to work.
I can get the 2x image included in srcset values if instead of using the image name handle I use the int[] for image size argument in my wp_get_attachment_image call.
echo wp_get_attachment_image(
get_post_thumbnail_id(),
[1280, 9999],
false,
[
'class' => 'object-cover object-center w-full h-full'
]
);
No real problem I guess, just seems a little silly that I have to name it in the first place. I apologize if I'm doing something dumb here....and I hope that's the case.
Any help appreciated!