Picture with serveral source and srcset
-
Hello,
In my project, I need to have different image on mobile and desktop. I also want to be able to manage responsive with sizes and also use webP.
Everything was fine until I installed the plugin. It made the srcset disappear even as I uninstall it 🙁I am therefore starting from the beginning. What did I miss?
<?php $photoID = get_field('photo'); // GET THE ID OF THE IMG ?> <picture> <source srcset="<?php echo wp_get_attachment_image_srcset($photoID, 'slider'); ?>" media="(min-width: 601px)"/> <source srcset="<?php echo wp_get_attachment_image_srcset($photoID, 'slider-mobile'); ?>" media="(max-width: 600px)"/> <img src="<?php echo wp_get_attachment_image_url($photoID, 'slider-mobile'); ?>" alt="" /> </picture>The objective is to obtain (on browser which support webp) :
<picture> <source srcset="slide-little.webp 300w, slide-medium.webp 650w, slide-large.webp 1000w" media="(min-width: 601px)"/> <source srcset="slidemobile-little.webp 300w, slidemobile-medium.webp 650w, slidemobile-large.webp 1000w" media="(max-width: 600px)"/> <img src="slidemobile-little.webp" alt="" /> </picture>Please help me!
Many thanks!
The topic ‘Picture with serveral source and srcset’ is closed to new replies.