Different image using srcset function


In a template I’m pulling in an image from the media library with:

<?php echo wp_get_attachment_image( 33894, 'full', "", array( "class" => "lazyload" ) ); ?>

This is working as I need it to, pulling in a nice large image for desktop.

Then when I look on the frontend, I see WordPress has generated images at different widths using srcset for a variety of widths, which is great for optimisation.

<img width="1240" height="831" src="https://www.mywebsite.com/wp-content/uploads/2021/12/cow-image.jpg" data-src="https://www.mywebsite.com/wp-content/uploads/2021/12/cow-image.jpg" class=" ls-is-cached lazyloaded " alt="My alt description" data- data-  >

Is it possible for me to write a function to hook into srcset and have an entirely different image for >768?

So use cow-image.jpg for desktop and duck-image.jpg for mobile/tablet?

Ordog 2 years 2021-12-18T16:31:33-05:00 0 Answers 0 views 0

Leave an answer