Find out in this tutorial how to use custom image sizes in WordPress image and gallery block using code.
In the previous tutorial you saw how to find out all the image sizes that a WordPress installation has.
But you probably noticed that, of all those sizes, only a few of them are available when you use the image or gallery block.
Usually only 3 are shown:
- Thumbnail
- Medium
- Large
But you may be interested in displaying some of the other sizes as well, even one that you have custom registered.
That’s why with this tutorial you are going to get a custom image size to appear in the dropdown of the WordPress image and gallery blocks as well.
Let’s take a look at it:
Snippet to use custom image sizes in WordPress image block
Add the following code at the end of functions.php or in your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
With this code you get to add 3 custom sizes to the dropdown, specifically:
- gb-block-post-grid-landscape -> GB Grid Landscape
- gb-block-post-grid-square -> GB Grid Square
- genesis-singular-images -> Genesis Singular
Of course, this is just an example. You can use any of the image sizes you get with this previous tutorial to add the ones you are interested into the dropdown.
Also, you can give any name you want to each of the sizes. Instead of “GB Grid Square” you can call it “Genesis Blocks Square” or whatever you prefer. 😉
Conclusions
Now you know how to add custom image sizes to the image or gallery block in WordPress.
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. 🙂