• 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

Get the image block default setting to be centered

Find out in this tutorial how to center the image block in WordPress by default using code.

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

For example, the image block is aligned to the left by default, but you can tell it to display centered and thus avoid having to change that setting every time you add a new image block.

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

Code to make the default setting of the image block centered

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 so that when you add the image block it is centered by default.

This is just an example, you can see the specific attributes that each block has in the official documentation.

Default setting with centered image

Now every time you add an image it will be centered.

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 image block and save a lot of time when entering the block.

Any questions? Let me know 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. 😉

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?