Learn in this tutorial how to hide block patterns added by a WordPress plugin or theme 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.
If you prefer that those added by a particular plugin or theme are not displayed, you can unregister them so that they are not displayed in the editor.
Snippet to hide block patterns of a WordPress plugin or WordPress theme from WordPress
Add the following snippet in functions.php:
In this snippet you use the
unregister_block_pattern function to unregister WooCommerce block patterns.
It is usual for the theme or plugin to register its block patterns with a prefix. In the case of WooCommerce it is
woocommerce/, but if you wanted to hide the ones in the Twenty Twenty-Two theme you would replace it with
The idea is that you change the prefix name to the one you want to hide. Remember that if you don’t know the prefix, you can use the tutorial that shows all the block patterns.
This strategy can also be interesting to hide the block patterns that WordPress adds without removing the ones that are loaded from the blocks directory. If you are interested in doing this, use this code
With this you will unregister all the block patterns that WordPress adds (keeping the ones in the directory), using a foreach loop.
On the other hand, if you want to disable both the native WordPress patterns and the directory ones, you can follow this other tutorial.
The arrival of block patterns in the WordPress editor opens up many 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 of a particular plugin or theme now you know how to disable them. 😉
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. 😉