0

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

1
  • 3
    Hey! Welcome to WPSE, I see you've not attached the code you're working with in the customizer, and you've not included the code that displays the image tags that you're trying to adjust either, use the Edit link to modify your question to include the missing code and provide more context about where it is and when it runs
    – Tom J Nowell
    Jun 21 at 15:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.