How to add srcset to post.thumbnail using the Timber template engine?

While using Timber in a WordPress theme, I would like to know how I can change the fetching of the tease-post.twig data so I could use the srcset attribute like so:

<img src=”{{ post.athumbnail.src }}” srcset=”{{ post.thumbnail.srcset }}”/>

When I open page.php the only thing I see that fetches the post data is $post = new TimberPost();.

So how would I change this query so the post thumbnail includes the WordPress generated srcset string that the wp_get_attachment_image_srcset function provides?

I did see some examples with image macro’s but that looks far to complex. Just a simple fetching of the data with wp_get_attachment_image_srcset and sending it off to the Twig template srcset attribute would be enough.

Read more here:: How to add srcset to post.thumbnail using the Timber template engine?

Leave a Reply

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