I maintain a lazy loading plugin, that got a bigger update a few days ago. Among other things, it was renamed to Lazy Loader, because it not only supports »only« images with the new version.
The plugin uses the small lazysizes script by Alexander Farkas. In a support thread, a user raised the question if it would be possible to include the unveilhooks extension of the script in the WordPress plugin, which allows things like lazy loading of background images. After that, I started with a bigger update, that contains the following changes:
Supporting more elements
Since version 3.2.0, the plugin supports – besides images – the auto-modification of the markup for lazy loading of the following elements in post content and widgets (you need to enable support for those elements via the plugin options under Settings › Media › Lazy Loader options):
- iFrames.
- Audio elements (needs the unveilhooks extension of lazysizes and loads it automatically, if the option is enabled).
- Video elements (also needs the unveilhooks script and loads it).
One other new option allows you to load the unveilhooks plugin regardless of the state of the audio and video options. With manual adjustment of the markup and loading the unveilhooks extension, you can also use lazy loading for the following elements:
- Background images.
- Styles.
- Scripts.
Besides the post content, the plugin now also supports widgets and Gravatars.
Moving the options to the media settings screen
The plugin options (until now that was only one option) lived in the customizer. After thinking about that, the customizer does not seem to be the right place for that kind of options, so I moved them to the media settings screen.
If you need a lazy loading plugin, give it a try 🙂
Hello,
Thanks for the plugin. Where can we find the instructions for manual modification of the markup.
I have images in my theme loaded with custom functions (a lot of them printed from the media url and srcset). I also have images printed from a background property in the css file.
Thanks for your help,
Hi,
here is an example (the markup of your comment avatar):
noscript
img
element with an empty (or the data image like in the above code)src
attribute.data-src
attribute with the image URL.lazyload
class.data-sizes
anddata-srcset
attributes.More info on the markup and options can be found in the docs of the lazy loading script.
Hope that helps!
Florian