Skip to content
Advertisement

WordPress: Use -tag with wp_get_attachment_image

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:

JavaScript

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:

JavaScript

Advertisement

Answer

Since 5.6.0, We get a way to wrap img elements.

JavaScript

The filter does not extract post_id but attachment_id. So if you want to activate the function systematically, You should link an attachment and its mobile image via post meta.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement