Lazy-Loading Images in Coming to WordPress Core
https://make.wordpress.orgWhile historically lazy-loading images has required a custom JavaScript-based approach, there is now a native web solution which relies solely on the presence of a new loading
attribute on img
tags and provides a standardized user experience without content shifting. The HTML specification for the loading attribute is near completion and is already supported by several browsers, including Chrome and Edge.
The implementation seeks to enable lazy-loading images by default, providing the loading
attribute with value lazy
on the following img
tags:
- Images in post content
- Images in post excerpts
- Images in comments
- Images in text widget content
- Individual images rendered via
wp_get_attachment_image()
- Avatar images rendered via
get_avatar()
While the images outlined above will be lazy-loaded by default, developers will be able to override this behavior both globally and on a per-image basis.
The proposed solution is available as a feature plugin WP Lazy Loading in the plugin repository. Β The current goal is to get this feature released as part of WordPress 5.4, merging in the next two weeks.