-
Notifications
You must be signed in to change notification settings - Fork 137
Fix missing PICTURE element support for post thumbnail and add missing Modern Image Formats support for Widget Block
#2179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix missing PICTURE element support for post thumbnail and add missing Modern Image Formats support for Widget Block
#2179
Conversation
|
@b1ink0 Code looks good, lets get some wider testing before landing. This PR also fixes the problem with working in image widgets (etc) - can you please update the description to include that? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #2179 +/- ##
==========================================
+ Coverage 68.65% 68.68% +0.03%
==========================================
Files 90 90
Lines 8091 8093 +2
==========================================
+ Hits 5555 5559 +4
+ Misses 2536 2534 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| */ | ||
| function webp_uploads_wrap_image_in_picture( string $image, string $context, int $attachment_id ): string { | ||
| if ( 'the_content' !== $context ) { | ||
| if ( ! in_array( $context, array( 'the_content', 'post_thumbnail_html', 'widget_block_content' ), true ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned #2178 (comment), I also added widget_block_content for testing the widgets. From my testing, adding widget_block_content as a context solves the issue for widgets. Should this be handled in a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind see #2179 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably, since its a separate issue entirely!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha! Cross path. Its fine to include in a single PR since the changes are tiny and its a bunch of extra work to add additional Issue and PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I’ll update this PR then.
PICTURE element support for post thumbnail and add missing Modern Image Formats support for Widget Block
| } | ||
| return webp_uploads_img_tag_update_mime_type( $html, 'post_thumbnail_html', $attachment_id ); | ||
| } | ||
| add_filter( 'post_thumbnail_html', 'webp_uploads_update_featured_image', 10, 3 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@adamsilverstein what do you think about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets avoid altering other plugin output for now, the unexpected change could break things or cause conflicts.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
westonruter
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to work with my testing. A diff from trunk:
--- before.html 2025-09-25 15:44:24
+++ after.html 2025-09-25 15:44:26
@@ -2518,24 +2518,35 @@
style="aspect-ratio: 3/2"
class="wp-block-post-featured-image"
>
- <img
- width="1200"
- height="1594"
- src="http://localhost:8000/wp-content/uploads/2025/09/Heimdall-PXL_20250919_195438368.MP-1200px-jpg.webp"
- class="attachment-post-thumbnail size-post-thumbnail wp-post-image"
- alt=""
- style="width: 100%; height: 100%; object-fit: cover"
- decoding="async"
- fetchpriority="high"
- srcset="
- http://localhost:8000/wp-content/uploads/2025/09/Heimdall-PXL_20250919_195438368.MP-1200px-jpg.webp 1200w,
- http://localhost:8000/wp-content/uploads/2025/09/Heimdall-PXL_20250919_195438368.MP-1200px-226x300-jpg.webp 226w,
- http://localhost:8000/wp-content/uploads/2025/09/Heimdall-PXL_20250919_195438368.MP-1200px-771x1024-jpg.webp 771w,
- http://localhost:8000/wp-content/uploads/2025/09/Heimdall-PXL_20250919_195438368.MP-1200px-768x1020-jpg.webp 768w,
- http://localhost:8000/wp-content/uploads/2025/09/Heimdall-PXL_20250919_195438368.MP-1200px-1156x1536-jpg.webp 1156w
- "
- sizes="(max-width: 1200px) 100vw, 1200px"
- />
+ <picture class="wp-picture-437" style="display: contents"
+ ><source
+ type="image/webp"
+ srcset="
+ http://localhost:8000/wp-content/uploads/2025/09/Heimdall-PXL_20250919_195438368.MP-1200px-jpg.webp 1200w,
+ http://localhost:8000/wp-content/uploads/2025/09/Heimdall-PXL_20250919_195438368.MP-1200px-226x300-jpg.webp 226w,
+ http://localhost:8000/wp-content/uploads/2025/09/Heimdall-PXL_20250919_195438368.MP-1200px-771x1024-jpg.webp 771w,
+ http://localhost:8000/wp-content/uploads/2025/09/Heimdall-PXL_20250919_195438368.MP-1200px-768x1020-jpg.webp 768w,
+ http://localhost:8000/wp-content/uploads/2025/09/Heimdall-PXL_20250919_195438368.MP-1200px-1156x1536-jpg.webp 1156w
+ "
+ sizes="(max-width: 1200px) 100vw, 1200px" />
+ <img
+ width="1200"
+ height="1594"
+ src="http://localhost:8000/wp-content/uploads/2025/09/Heimdall-PXL_20250919_195438368.MP-1200px.jpg"
+ class="attachment-post-thumbnail size-post-thumbnail wp-post-image"
+ alt=""
+ style="width: 100%; height: 100%; object-fit: cover"
+ decoding="async"
+ fetchpriority="high"
+ srcset="
+ http://localhost:8000/wp-content/uploads/2025/09/Heimdall-PXL_20250919_195438368.MP-1200px.jpg 1200w,
+ http://localhost:8000/wp-content/uploads/2025/09/Heimdall-PXL_20250919_195438368.MP-1200px-226x300.jpg 226w,
+ http://localhost:8000/wp-content/uploads/2025/09/Heimdall-PXL_20250919_195438368.MP-1200px-771x1024.jpg 771w,
+ http://localhost:8000/wp-content/uploads/2025/09/Heimdall-PXL_20250919_195438368.MP-1200px-768x1020.jpg 768w,
+ http://localhost:8000/wp-content/uploads/2025/09/Heimdall-PXL_20250919_195438368.MP-1200px-1156x1536.jpg 1156w
+ "
+ sizes="(max-width: 1200px) 100vw, 1200px"
+ /></picture>
</figure>
<div class="wp-block-post-date">
Summary
Fixes #2178
Relevant technical choices
This PR fixes the
webp_uploads_update_featured_imagefunction not outputting the<picture>element for featured image when the experimental picture element setting is enabled.Also fixes a issue where image blocks used inside widgets (like Image and Gallery blocks) weren’t getting replaced with modern formats.