• Skip to primary navigation
  • Skip to main content
OsomCode

OsomCode

Awesome code tutorials for WordPress and Genesis

  • Subscribe
  • My account
    • Edit profile
    • Favorites
    • Update credit card
  • Login

How to customize the default settings for WordPress gallery block

Discover in this tutorial how to customize the default settings of the gallery block using code.

WordPress native blocks come with default settings. That is, when you enter the block, they already have the settings of the block and, although you can change them from the block editor, it is possible that in some of them you will always have to modify some setting.

For example, the gallery block crops the images by default, but you can tell it not to do so and thus avoid having to change that setting every time you add a new gallery block. And for the same price you can set the default link or size.

In this tutorial we will see how you can do that.

Code to customize the default attributes of the gallery 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.

In this snippet you use the block_type_metadata filter to customize the default gallery block settings.

In the attributes you indicate:

  • imageCrop: if true it crops the image, if false it does not.
  • linkTo: indicate the destination of the image(attachment, media, none).
  • sizeSlug: specify the size of the image(thumbnail, medium, large, full).

You can see the specific attributes that each block has in the official documentation.

In the example above you get the following:

  • That the images are not cropped.
  • That the images are not linked, so you can use the native WordPress lightbox.
  • That the default size of the image is the medium size and that the image opens in a new page.
Default gallery block settings

Now every time you add a gallery it will have these settings selected.

And if in any case you want to modify them, you will be able to do it without any problem.

Conclusion

Thanks to the block_type_metadata filter you can decide which are the default settings of the gallery block and save a lot of time when entering the block.

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. 🙂

Block Editor PHP WordPress

To leave read and make questions about this code, you can login or register.

  • About OsomCode
  • FAQ
  • Contact

Legal Notice · Privacy Policy · Cookie Policy · Terms and conditions
Copyright © 2026

close-icon

Lost your password?