I’m having trouble finding the “Wordpress-y” way of modifying the markup of the <img> tags in a given post.
For context, I’m trying to integrate https://github.com/verlok/lazyload into a theme I’m developing, and as such I need to replace every image tag’s src attribute with data-src.
I tried hooking into the wp_get_attachment_image_attributes filter, but that didn’t seem to do the trick.
This is more of a general WordPress question than a Sage question, but it may be a little challenging to filter the HTML used for images in the body of posts, because after you insert it into the post content (e.g., using the visual editor), the HTML has already been generated.
But besides having to update any existing content, filtering it there might mean that your images don’t show up in the editor unless you also use the lazy loader on the editor–not ideal.
To avoid that, you would probably need to filter the_content, parse the HTML to find images, and replace the image markup with the modified markup you need.
if you don’t want to use a plugin, you can probably find examples of people filtering image tags in the_content to help avoid having to entirely reinvent the wheel.