[wp-trac] [WordPress Trac] #61847: Auto Sizes for Lazy-loaded Images

WordPress Trac noreply at wordpress.org
Wed Sep 4 16:51:06 UTC 2024


#61847: Auto Sizes for Lazy-loaded Images
--------------------------------------+--------------------------
 Reporter:  mukesh27                  |       Owner:  mukesh27
     Type:  enhancement               |      Status:  assigned
 Priority:  normal                    |   Milestone:  6.7
Component:  Media                     |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  performance
--------------------------------------+--------------------------

Comment (by flixos90):

 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:23>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list