Hi, I’m creating a WP plugin with a custom dynamic block and I need to customize the srcset
attribute in the image I’m using.
To do that, I can simply add a “function” smart action and change the attribute directly by using PG_Blocks::getImageUrl()
like this:
echo PG_Blocks::getImageUrl( $args, 'my_block_image', 'medium_large' ) . ' 1x, ' . PG_Blocks::getImageUrl( $args, 'my_block_image', 'large' ) . ' 2x';
Well, the generated block PHP code is broken (which is related to #7632), but even if I correct it manually in the block code, setting the image size in the getImageUrl()
method to, let’s say, medium_large
, large
or any other value that is not medium
, always return the medium
size.
I noticed that the same occurs when I select another image site in the “use as image” field on a regular Javascript block. The method does not respect the requested image size. So it’s not a PHP thing.
Here’s a test project if you need to take a look.