Discover in this tutorial how to change the image size of WordPress featured image block with a little bit of code.
The featured image block of the post is very interesting to use in post listings or as post header.
The catch is that you can’t choose the image size it uses (thumbnail, medium….) and this can cause a page, especially if displaying a listing with many entries, to weigh much more than necessary.
Fortunately, there is a filter that allows you to choose the size easily. Let’s see how.
Snippet to change the size of the featured image
Add the following code at the end of functions.php or in your functionality plugin:
In this code you use the
render_block_data filter to identify the gallery blocks
(core/post-featured-image) and modify the
sizeSlug attribute that controls the size of the image to be displayed.
In the example above you indicate that it should display the
medium size, but you can use any of the sizes that are registered in WordPress installation.
If you are interested that this only applies to certain pages or blocks you can combine the above code with conditional tags.
Now you know how to control what size featured images are displayed in WordPress with a little bit of code.
Any questions? I read you in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉