[wp-trac] [WordPress Trac] #58631: decoding="async" is added wildly, even if loading="eager" is there

WordPress Trac noreply at wordpress.org
Mon Jun 26 14:54:25 UTC 2023


#58631: decoding="async" is added wildly, even if loading="eager" is there
--------------------------+-----------------------------
 Reporter:  vyskoczilova  |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  6.2.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Could we do something about {{{decoding="async"}}} parameter being added
 wildly on EVERY image?

 It might seem to be a good idea, but it's not. I'm developing custom
 themes, and although it was introduced in 6.1, it touched me probably with
 some changes in 6.2 where {{{ wp_filter_content_tags() }}} is replacing
 images without the parameter (and {{{wp_get_attachment_image_attributes}}}
 filter is not called in this case. I was using loading="eager" for my hero
 images (rendered in the template via Timber) which should be a no-no to
 adding decoding="async" for that.

 I might help to fix the issue if somebody guides me through track and svn
 (but I'm fluent in git repos if there is finally a way to contribute this
 way).

 Suggesting - checking for fetch priority and loading=eager params, and if
 present, do not add {{{decoding="async"}}} or {{{loading="lazy."}}}

 I'm currently doing this, but it's silly to be fixing it on every site:

 {{{#!php
 <?php
 add_filter( 'wp_content_img_tag', function( $filtered_image, $context,
 $attachment_id ) {

     // search in the filtered_image html string for loading="eager" and if
 present, remove decoding="async"
     if ( false !== strpos( $filtered_image, 'loading="eager"' ) || false
 !== stripos( $filtered_image, 'fetchpriority="high"' ) ) {
         $filtered_image = str_replace( ' decoding="async"', '',
 $filtered_image );
     }

     return $filtered_image;
 }, 10, 3 );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58631>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list