Hi and thanks for the feedback. I’ll try to answer your questions one by one.
I need a lazy load plugin that works with the picture element, as all the others except for one, do not support this element.
I haven’t explicitly tested the plugin with the picture element, but if my memory is correct, the plugin doesn’t transform the picture element html to be lazy loading friendly yet. The lazysizes library should support this, so I’ll try to get this added in the future.
I am having trouble with the Extra/Divi theme by Elegant Themes. Do you know how to make your plugin compatible with this theme?
I can look into it, but it would depend on how the theme is coded. If the theme is using wp_get_attachment_image that could be one reason why it doesn’t work.
How do you recommend changing it to get_lazysizes_html( wp_get_attachment_image($id) as you suggest?
There’s sadly no easy way. You could just replace wp_get_attachment_image($id) (or whatever the $id part is named in the theme code) with get_lazysizes_html( wp_get_attachment_image($id), but that would break on theme update. I would recommend making a child theme (see the child theme docs), copying the files using wp_get_attachment_image and changing them in the child theme instead, which would make sure they don’t get overwritten. It is also possible that your theme has built-in hooks for changing stuff like this (so you wouldn’t have to copy whole files), but I’m not sure. The themes documentation should specify that. I can see if I can find out if that’s the case. Also, as you might have understood, this does require a bit of technical knowledge at the very least.
Is there any reason this plugin doesn’t natively support wp_get_attachment_image?
wp_get_attachment_image generates a complete string of HTML code for an image tag, and I’m not aware of any way this plugin could influence this HTML to allow for lazy-loading. I can do some research to see if there is a way (maybe see what other plugins are doing), but until then, I’m afraid the plugin can’t support it.
Upon further inspection it appears that I could use the hook wp_get_attachment_image_attributes to modify the image attributes. I will do some testing and see if I can add this to the next version of the plugin.
Again, thanks very much for your feedback. It is greatly appreciated, and as you said, could help me make this plugin benefit more people. I’ll make sure to see what I can do.
– Patrick Sletvold
-
This reply was modified 5 years, 9 months ago by Patrick Sletvold. Reason: Updated info