php – WordPress: Use <picture>-tag with wp_get_attachment_image-ThrowExceptions

Exception or error:

I want to use the <picure>-tag with the function wp_get_attachment_image.
At the moment I’m getting an <img>-tag with srcset. That’s nice but is there any way to change it to a <picure>-tag with multiple sources in it? Like this:

  <source media="(min-width: 56.25em)" srcset="large.jpg 1x, large@2x.jpg 2x">
  <source media="(min-width: 37.5em)" srcset="medium.jpg 1x, medium@2x.jpg 2x">
  <source srcset="small.jpg 1x, small@2x.jpg 2x">
  <img src="fallback.jpg" alt="">

I need that because I want to display a second version of the image. So I can have horizontal and vertical images in one <picture>-tag. Like this:

  <source media="(min-width: 38em)" srcset="art-direction-horizontal.jpg">
  <source srcset="art-direction-vertical.jpg">
  <img src="art-direction-vertical.jpg" alt="">
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *