Discover in this tutorial how to unregister native WordPress blocks using code.
Since a few versions of WordPress, you have the option to hide the blocks that you don’t want to be displayed in the editor
You can do this by clicking on the three dots at the top left and selecting: Tools > Block Manager.
But this does not prevent the blocks from being loaded and accessible from the manager for other users.
Therefore, you may want to cut to the chase and simply unregister these blocks so that they are not loaded in the editor.
Is this the case for you? Here is how to do it.
Steps to unregister native blocks of the WordPress editor
1. Create a file unregister-blocks.js
Insert this snippet into a new file named unregister-blocks.js inside the /lib/js/ folder:
If the /js/ folder does not exist, create it. Or if you prefer to place it in another path in the theme, you can do it, just make sure to change it in the next step as well.
This script uses the
unregisterBlockType function to unregister the blocks you are interested in.
With the example above, you are unregistering the verse block and tag cloud, but at the end of the tutorial you will find a list of all the native blocks so you can customize it to your liking.
2. Enqueue the file unregister-blocks.js
Now, paste the following block at the end of the functions.php file of your WordPress theme:
With these lines you get the theme to load the
WordPress native blocks
Here you have the list with all the WordPress native blocks:
With this information you can add all the blocks you want to remove to the snippet in step 1.
Do you prefer to stop loading native blocks that you won’t use? Or that you don’t want your client to see? Well, now you know how to unregister them with a little bit of code.
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. 🙂