[wp-trac] [WordPress Trac] #61847: Auto Sizes for Lazy-loaded Images
WordPress Trac
noreply at wordpress.org
Sat Mar 1 06:50:47 UTC 2025
#61847: Auto Sizes for Lazy-loaded Images
-------------------------------------------------+-------------------------
Reporter: mukesh27 | Owner: joemcgill
Type: enhancement | Status: closed
Priority: normal | Milestone: 6.7
Component: Media | Version:
Severity: normal | Resolution: fixed
Keywords: has-patch has-unit-tests needs-dev- | Focuses:
note | performance
-------------------------------------------------+-------------------------
Comment (by oxfordmetadata):
Replying to [comment:23 flixos90]:
I have tried your filter but it does not appear to work. We are still
observing the presence of
<style>img:is([sizes="auto" i], [sizes^="auto," i]) { contain-intrinsic-
size: 3000px 1500px }</style>
So pagespeed gives penalizing our sites.
Any ideas?
> Pending @joemcgill's review, I think the PR is ready for commit.
>
> Regarding the discussion on introducing a potential filter, in addition
to what's already been discussed on the PR, it's worth noting that it's
already possible to disable the `auto` keyword with filters already
present, e.g. by doing this:
>
> {{{#!php
> <?php
> add_filter(
> 'wp_content_img_tag',
> static function ( $image ) {
> return str_replace( ' sizes="auto, ', ' sizes="', $image
);
> }
> );
> add_filter(
> 'wp_get_attachment_image_attributes',
> static function ( $attr ) {
> if ( isset( $attr['sizes'] ) ) {
> $attr['sizes'] = preg_replace( '/^auto, /', '',
$attr['sizes'] );
> }
> return $attr;
> }
> );
> }}}
>
> Given that there's no good reason to generally disable the feature, I
think the presence of these two filters is sufficient to alter the
behavior if needed. Both of them have the image context available, so they
could also alter the presence of `auto` based on what the image is.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61847#comment:35>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list