# WordPress blocks: can't define the image size manually in “function” smart action

**URL:** <https://forum.pinegrow.com/t/wordpress-blocks-cant-define-the-image-size-manually-in-function-smart-action/8044>\
**Category:** Blocks\
**Tags:** bug, wordpress, blocks\
**Created:** [May 19, 2023, 3:30pm UTC](https://forum.pinegrow.com/t/wordpress-blocks-cant-define-the-image-size-manually-in-function-smart-action/8044 "2023-05-19T15:30:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marc\_io](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/marc_io/32/3431_2.png) [@marc\_io](https://forum.pinegrow.com/u/marc_io)\
**Post date:** [May 19, 2023, 3:30pm UTC](https://forum.pinegrow.com/t/wordpress-blocks-cant-define-the-image-size-manually-in-function-smart-action/8044/1 "2023-05-19T15:30:54Z")

</div>

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:

```php
echo PG_Blocks::getImageUrl( $args, 'my_block_image', 'medium_large' ) . ' 1x, ' . PG_Blocks::getImageUrl( $args, 'my_block_image', 'large' ) . ' 2x';

```

 ![requesting-different-image-sizes](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/5/5e166095d82d178c3b01177b6cfb4e54802fe6da.png)

Well, the generated block PHP code is broken (which is related to [#7632](https://forum.pinegrow.com/t/setting-srcset-block-attribute-on-a-source-element-fails/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.

 ![all-medium-sizes](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/c/c6ae8088900c22a038c21717876f2f14ba9d0d4b.png)

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.

 ![setting-different-image-size](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/c/cd6586c253e0e106aa882d717f0ce3bd631ee3e6.png)

[Here’s a test project](https://dl.dropbox.com/s/pin13ou6ox0y7gl/test.zip) if you need to take a look.

---

<div class="post-metadata">

**Author:** ![marc\_io](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/marc_io/32/3431_2.png) [@marc\_io](https://forum.pinegrow.com/u/marc_io)\
**Post date:** [May 19, 2023, 11:45pm UTC](https://forum.pinegrow.com/t/wordpress-blocks-cant-define-the-image-size-manually-in-function-smart-action/8044/2 "2023-05-19T23:45:10Z")

</div>

I ended up using the `getImageField()` from Pinegrow to get the image ID and then the native WordPress function `wp_get_attachment_image_src` to get the URL of the correct image size.

```php
// Get the image ID.
$img_id = PG_Blocks::getImageField( $args, 'my_block_image', 'id', true);

// Get the correct URL for the intended image size.
$img_url = wp_get_attachment_image_src( $img_id, 'medium' )[0];

```

It solves both the broken generated code and the issues with the incorrect image size.
