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
Only replace content images with additional MIME type version when in a frontend request context by default #379
To help address concerns around WebP compatibility, we should ensure that WebP images are used by default for the content only in the front end (or "template") context.
Critically, when content is filtered outside this context - for example in REST endpoints and RSS feeds, the original mime type should be used by default (ew can leverage the existing filter here to make this customizable). In addition, core functions like wp_get_attachment_image_url which would be used to generate Open Graph tags should always return the original MIME type unless called in the template context.
Some research is needed on the best approach here to ensure template context is recognized and image replacement works in places like widgets or images placed in FSE headers while feeds and REST endpoints remain unaffected. We can possibly leverage template_redirect to ensure we are in the "right" loop.
After thinking about this further, we should probably rely on checking for both the template_redirectandwp_head hooks to have been completed, for the following reason:
template_redirect indicates most reliably that we are in a frontend request context.
wp_head is only for "invisible" content like meta tags etc so we shouldn't replace images with WebP there.
We can use did_action() for that, but we also need to make sure that they actions aren't running anymore, so we also need to check for doing_action() (since did_action() does only mean the action fired, not necessarily that it already completed). In other words we should only replace images under the following conditions:
@akshitsethi I see that you've assigned this to yourself; a reminder that we'll want to have this in good shape by 13 July or so for the 1.3.0 release.
Activity
felixarntz commentedon Jun 25, 2022
After thinking about this further, we should probably rely on checking for both the
template_redirectandwp_headhooks to have been completed, for the following reason:template_redirectindicates most reliably that we are in a frontend request context.wp_headis only for "invisible" content like meta tags etc so we shouldn't replace images with WebP there.We can use
did_action()for that, but we also need to make sure that they actions aren't running anymore, so we also need to check fordoing_action()(sincedid_action()does only mean the action fired, not necessarily that it already completed). In other words we should only replace images under the following conditions:mxbclang commentedon Jul 1, 2022
@akshitsethi I see that you've assigned this to yourself; a reminder that we'll want to have this in good shape by 13 July or so for the 1.3.0 release.
adamsilverstein commentedon Jul 7, 2022
Note that we'll also need to add this check when we add support for altering the featured image automatically in
_wp_post_thumbnail_html