Help with PHP/Gutenberg and HTML image rendering

[ad_1]

Hello fellow developers,

I am currently working on a side project using WP as my headless CMS which I consume via the REST API. When I retrieve the post’s rendered content (post.content.rendered) my images are rendered like this:

<figure class=”wp-block-image size-large”>
<img decoding=”async” src=”image.jpg” />
</figure>

How can I customize this output HTML, so that I can edit the `img` tag attributes? What I would like to do on my frontend is add lazyloading and reduce layout shift, which is typically achieved via HTML attributes and CSS. Ideally my output would look something like this:

<figure class=”wp-block-image”>
<img loading=”lazy” data-src=”image.jpg” />
</figure>

Thanks!

Ricky

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer