Skip to content

Only replace content images with additional MIME type version when in a frontend request context by default #379

Closed

Description

@adamsilverstein

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.

Activity

  1. added this to the 1.3.0 milestone on Jun 15, 2022
  2. felixarntz commented on Jun 25, 2022

    @felixarntz
    Member

    After thinking about this further, we should probably rely on checking for both the template_redirect and wp_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:

    did_action( 'template_redirect' ) && did_action( 'wp_head' ) && ! doing_action( 'wp_head' )
    
  3. self-assigned this
    on Jun 28, 2022
  4. mxbclang commented on Jul 1, 2022

    @mxbclang
    Contributor

    @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.

  5. removed
    Needs DevAnything that requires development (e.g. a pull request)
    on Jul 5, 2022
  6. adamsilverstein commented on Jul 7, 2022

    @adamsilverstein
    MemberAuthor

    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

  7. self-assigned this
    on Jul 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions