Learn in this tutorial how to hide some block patterns from WordPress editor using code.
WordPress 5.5 introduced quite a few new features and, among them, the option to use block patterns in the editor.
In a WordPress installation there can be several patterns, some added by the WordPress core and others by themes (and/or plugins). That’s why, in a recent tutorial I explained how you can visualize all the block patterns registered in a WordPress installation.
If you prefer some of them not to be displayed, you can unregister them so that they are not displayed in the editor.
Snippet to hide some block patterns in WordPress editor
Add the following snippet in functions.php:
In this snippet you use the
unregister_block_pattern function to unregister the social media links block pattern that WordPress adds (core/social-links-shared-background-color).
The idea is that you change the name of the block pattern to the one you want to hide.
If you want to hide multiple patterns I recommend using this strategy:
In this case, you are unregistering all the block patterns that WordPress adds, using a foreach loop.
Add or remove the patterns you want to customize it to your liking.
The arrival of block patterns in the WordPress editor opens up a lot of possibilities. And it’s easy for the new section to be filled with patterns from themes or plugins.
So, if you (or your client) are not going to use some patterns now with this tutorial you know how to disable them. 😉
This is also especially interesting if you are creating your own theme or plugin and intend to add your own patterns.
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. 😉