You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Modern Image Formats - post thumbnail dont follow picture element #2178
No others plugins installed, only Modern Image Formats with settings
AVIF - Generate images in this format
✓ Also generate fallback images in the original upload format
✓ Generate all fallback image sizes including custom sizes
✓ Use < picture > Element (experimental)
And, right now we are using the post_thumbnail_html filter for the featured image, but we could use the wp_get_attachment_image filter as the bug reporter suggested. However, this filter would also include any image echoed using the wp_get_attachment_image() function, which is used for featured images and is also typically used by other plugins. So, I'm not sure whether the Modern Image Formats plugin should also handle those images.
Also, while trying to replicate this bug, I noticed that (Using Twenty Twenty-One) Image Widgets or widget blocks containing the Image block and Gallery block don’t get their sources replaced with modern image formats because the webp_uploads_wrap_image_in_picture() function only allows the the_content context, while widgets send the widget_block_content context. @adamsilverstein, is this intentional?
Thanks for your answer. How about a new checkbox "experimental use of wp_get_attachment_image()" in the settings? If users don't report any issues in future, it could be used in the plugin itself as the default.
the Image block and Gallery block don’t get their sources replaced with modern image formats because the webp_uploads_wrap_image_in_picture() function only allows the the_content context, while widgets send the widget_block_content context. @adamsilverstein, is this intentional?
I don't think so - seems like and oversight. it should be fine to enable for the widget context. I think we added that conditional to avoid replacing images in places like an the RSS feed where modern formats might not be accepted.
It seems the issue is with the webp_uploads_update_featured_image() function hooked to post_thumbnail_html, which only calls webp_uploads_img_tag_update_mime_type() and does not conditionally call webp_uploads_wrap_image_in_picture() based on webp_uploads_is_picture_element_enabled().
@b1ink0 - can you try adding that logic to webp_uploads_update_featured_image in a PR for testing? We need to make sure there aren't unexpected side effects. If everything works as expected we can change this.
How about a new checkbox "experimental use of wp_get_attachment_image()" in the settings? If users don't report any issues in future, it could be used in the plugin itself as the default.
@1ucay thanks for the bug report! Adding another UI controlled option in settings feels like it might confuse casual users, let's see how this works and maybe returning a picture element should just be the default. It's certainly what you expected.
We can also consider a hook that would enable developers to control the option. Users already have a UI option to turn off the picture element feature.
@adamsilverstein created a draft PR to test side effects (#2179). In my testing with the TT5 theme, it did not affect the layout and correctly added the <picture> element for the featured image.
Activity
1ucay commentedon Sep 16, 2025
My fix
b1ink0 commentedon Sep 17, 2025
I was able to replicate this bug. It seems the issue is with the
webp_uploads_update_featured_image()function hooked topost_thumbnail_html, which only callswebp_uploads_img_tag_update_mime_type()and does not conditionally callwebp_uploads_wrap_image_in_picture()based onwebp_uploads_is_picture_element_enabled().And, right now we are using the
post_thumbnail_htmlfilter for the featured image, but we could use thewp_get_attachment_imagefilter as the bug reporter suggested. However, this filter would also include any image echoed using thewp_get_attachment_image()function, which is used for featured images and is also typically used by other plugins. So, I'm not sure whether the Modern Image Formats plugin should also handle those images.Also, while trying to replicate this bug, I noticed that (Using Twenty Twenty-One) Image Widgets or widget blocks containing the Image block and Gallery block don’t get their sources replaced with modern image formats because the
webp_uploads_wrap_image_in_picture()function only allows thethe_contentcontext, while widgets send thewidget_block_contentcontext. @adamsilverstein, is this intentional?1ucay commentedon Sep 17, 2025
Thanks for your answer. How about a new checkbox "experimental use of wp_get_attachment_image()" in the settings? If users don't report any issues in future, it could be used in the plugin itself as the default.
adamsilverstein commentedon Sep 19, 2025
I don't think so - seems like and oversight. it should be fine to enable for the widget context. I think we added that conditional to avoid replacing images in places like an the RSS feed where modern formats might not be accepted.
@b1ink0 - can you try adding that logic to
webp_uploads_update_featured_imagein a PR for testing? We need to make sure there aren't unexpected side effects. If everything works as expected we can change this.@1ucay thanks for the bug report! Adding another UI controlled option in settings feels like it might confuse casual users, let's see how this works and maybe returning a picture element should just be the default. It's certainly what you expected.
We can also consider a hook that would enable developers to control the option. Users already have a UI option to turn off the picture element feature.
b1ink0 commentedon Sep 19, 2025
@adamsilverstein created a draft PR to test side effects (#2179). In my testing with the TT5 theme, it did not affect the layout and correctly added the
<picture>element for the featured image.adamsilverstein commentedon Sep 19, 2025
That looks great @b1ink0, thanks! I will try to spend some time testing further soon.
@1ucay can you test the PR (#2179) to verify it resolves your issue?
1ucay commentedon Sep 22, 2025
Dear all,
yes with PR #2179 working ok 👍 Thank you