I'm trying to apply custom data-src
and srcset
attributes to images added in Customiser. The page is static with no loop and I have so far hard coded the data-src attribute with <?php echo wp_get_attachment_url( get_theme_mod( 'hero_img' ) ); ?>
so it will take the url of the image selected by the user.
I presume adding srcset
and sizes
attributes could be done similarly, however I can't figure out how to unset the src
attribute so that I can populate this using the value of data-src
instead (for lazy loading). I've searched everywhere for an answer but all the solutions to similar problems involve the_content()
or filters I don't have access to without a loop.
Surely there has to be an easier way to get responsive images and custom attributes working with a static site that has customiser fields to change media?
Any help would be massively appreciated, I'm probably going about this all wrong.
Many Thanks
Edit
link to modify your question to include the missing code and provide more context about where it is and when it runs