I have a lot posts converted from classic editor to block editor and in the process, some image blocks (or all) have missing sizeSlug attribute, which editor interpretes as thumbnail size. However, I have new posts as well and they have size slug. I want to add to all image blocks attribute sizeSlug set to 'large', which are missing this attribute.

I would know how to do it with wp cli and regex if it weren't for those posts which already have this attribute and who should not be touched.

Example of markup of image without sizeSlug:

<!-- wp:image {"align":"center","id":13431,"linkDestination":"custom"} -->
<figure class="wp-block-image aligncenter"><a href="https://host/wp-content/uploads/2020/02/friends.jpg"><img src="https://host/wp-content/uploads/2020/02/friends.jpg" alt="Friends" class="wp-image-13431"/></a></figure>
<!-- /wp:image -->

Solution which affects all block images, which adds sizeSlug to all image blocks:

wp search-replace '(<!-- wp:image\s{[^}]*)' '$1,"sizeSlug":"full"' wp_posts --regex --regex-delimiter='/'

The answer does not have to be wp cli based.

1 Answer 1


It seems that this regex does the trick:

wp search-replace '(<!-- wp:image\s{(?!.*"sizeSlug")[^}]*)' '$1,\"sizeSlug\":\"full\"' wp_posts --regex --regex-delimiter='/' --precise

EDIT: I added correction, double quotes must be escaped in replacement string in order for this to work properly. It seems that everything is first encoded in json, hence the reason.

ANOTHER EDIT: This did the trick by updating post content by adding attribute, but srcset and sizes are still missing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.