Lazy load missed images (wp_get_attachment_image)

Some images aren’t automatically lazy loaded by most plugins. These are usually thumbnails added by your theme, plugins, or in your sidebar. Those images are almost always added by the function wp_get_attachment_image.

There are two reasons we’ve seen that these are skipped:

  1. Can’t add necessary attribute and/or noscript support.
  2. Conflicts with certain themes/plugins.

However, it is possible to lazy load these, although it typically needs to be done on a case-by-case basis.

WP Rocket Load

There are two options:

  1. Use the code WP Rocket wrote. This works without much effort, but users who disable JavaScript will not see these images (other images will work as usual).
  2. Write some special code into your theme. This takes more work, and only works for theme-related images (not plugins or widgets) but has better support for users who have disabled JavaScript.

Auto-enable:
https://github.com/wp-media/wp-rocket/blob/v3.2/inc/front/lazyload.php#L273

Manually add:
https://gist.github.com/glueckpress/08d9cd875ceec64bd31798c5325d2197

Lazy Load XT

This plugin only has the latter option, of the two available with WP Rocket: manually update your theme to enable lazy loading. They provide a function for this: https://github.com/dbhynds/lazy-load-xt#why-arent-my-images-lazy-loading