[wp-trac] [WordPress Trac] #58895: Make it easier to override default loading optimizations

WordPress Trac noreply at wordpress.org
Mon Jul 24 19:01:10 UTC 2023


#58895: Make it easier to override default loading optimizations
-------------------------+-------------------------
 Reporter:  joemcgill    |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  6.4
Component:  Media        |    Version:  trunk
 Severity:  normal       |   Keywords:  needs-patch
  Focuses:  performance  |
-------------------------+-------------------------
 In [56037] (see #58853) a new set of functions were added to dynamically
 add loading optimization attributes, like `loading="lazy"` and
 `fetchpriority="high"` to images and iframes.

 The main function responsible for this behavior is
 `wp_get_loading_optimization_attributes()`, which is called directly in
 several other places in core, like
 `wp_img_tag_add_loading_optimization_attrs()` and
 `wp_iframe_tag_add_loading_attr()`. However, there doesn't seem to be a
 straightforward way to disable or override this functionality globally.

 Similar functions that are dynamically run on rendered HTML, like
 `wp_img_tag_add_srcset_and_sizes_attr()` and
 `wp_img_tag_add_width_and_height_attr()` have filters in place that allow
 you to disable that functionality if you want to remove it or implement
 your own processing via the `wp_content_img_tag` hook instead.

 `wp_img_tag_add_loading_optimization_attrs` has a hook to filter the
 return value, but not until after `wp_get_loading_optimization_attributes`
 has been called, which
 unfortunately produces side effects by calling
 `wp_increase_content_media_count()` or changing the value of
 `wp_high_priority_element_flag()`.

 Ideally, you could disable just the optimizations applied to rendered
 markup via a filter in `wp_img_tag_add_loading_optimization_attrs()` in
 case you needed to override just that functionality. However,
 `wp_get_loading_optimization_attributes()` should also be easier to
 override or turn off entirely so implementors could enhance core's
 defaults with their own optimization techniques.

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


More information about the wp-trac mailing list