I'm trying to set the srcset
property of a block image.
I'm replacing the image with another one and I noticed the attribute srcset
is not being set, so I'm trying this with no success:
wp.data.dispatch('core/block-editor').updateBlock(blockId, {
attributes: {
id: imageData.id,
url: imageData.url,
srcset: imageData.srcset,
},
});
Am I missing something?
The image gets displayed like this on post, without the srcset
attribute for different resolutions:
<figure class="wp-block-image size-full"><img decoding="async" src="https://example.com/epa/wp-content/uploads/2023/06/demo-9.jpg" alt="" class="wp-image-3528"></figure>
The code editor code has no difference with normally upload images with srcset. So I assume there's nothing wrong on this part:
<!-- wp:image {"id":3546,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://example.com/epa/wp-content/uploads/2023/06/demo-9.jpg" alt="this is a demo" class="wp-image-3546"/></figure>
<!-- /wp:image -->
srcset
attribute once I modify the block with the new path and publish it.