[wp-trac] [WordPress Trac] #44427: Introduce lazy-loading API for media and other elements

WordPress Trac noreply at wordpress.org
Wed Mar 25 02:16:01 UTC 2020


#44427: Introduce lazy-loading API for media and other elements
-------------------------------------------------+-------------------------
 Reporter:  mor10                                |       Owner:  flixos90
     Type:  feature request                      |      Status:  assigned
 Priority:  normal                               |   Milestone:  5.5
Component:  Media                                |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests 2nd-        |     Focuses:
  opinion early needs-testing                    |  performance
-------------------------------------------------+-------------------------
Changes (by azaozz):

 * keywords:  has-patch has-unit-tests 2nd-opinion early => has-patch has-
     unit-tests 2nd-opinion early needs-testing


Comment:

 In 44427.9.diff: Merge patch for the https://github.com/WordPress/wp-lazy-
 loading plugin.
 - Introduces `wp_lazy_loading_enabled()` helper function to easily enable
 or disable adding of the loading attribute for specific contexts.
 - Introduces `wp_filter_content_tags()` that adds srcset, sizes and
 loading attributes to img tags (for now). Will eventually be used to add
 loading attribute to iframes. Replaces
 `wp_make_content_images_responsive()`.
 - Introduces `wp_img_tag_add_loading_attr()` and
 `wp_img_tag_add_srcset_and_sizes_attr()` to go with
 `wp_filter_content_tags()`.
 - Adds `loading="lazy"` to image tags on the_content, the_excerpt, and
 widget_text_content filters (front-end) by default. These can be disabled
 or changed by specifying a `loading` attribute before the filter, by using
 `wp_lazy_loading_enabled()` and the specific context (the filter name is
 used as context), or by using the `wp_img_tag_add_loading_attr` filter
 that runs before adding the attribute to each img tag.
 - Adds `loading="lazy"` to `wp_get_attachment_image()` and `get_avatar()`
 by default. Can be disabled by using `wp_lazy_loading_enabled()` (context
 will be `wp_get_attachment_image` or `get_avatar` respectively), or by
 passing a value for the loading attribute.

 Please test! :)

 Alternatively test the [https://wordpress.org/plugins/wp-lazy-loading/ WP
 Lazy Loading plugin] that has identical functionality/code.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44427#comment:97>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list