Discover in this tutorial how to unregister Genesis Blocks using code.
Since a few versions of WordPress, you have the option to hide the blocks that you do not 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.
That’s why in a previous tutorial I explained how to unregister the native blocks of the WordPress editor. In this case, you are going to see how to achieve the same thing but with Genesis Blocks.
Steps to unregister blocks from Genesis Blocks
1. Create a file unregister-blocks.js
Insert this snippet into a new file named unregister-header.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 that, 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.
In this case, you are unregistering the column block (global and individual) and the spacer block. This way you avoid confusion with the native blocks of this type. Although if you prefer you could leave these and remove the native ones.
In any case, at the end of the tutorial you will find a list with all the Genesis Blocks so you can customize the snippet 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
Genesis Blocks blocks
Here you have the list with all the blocks included in Genesis Blocks:
With this information you can add all the blocks you want to remove to the snippet in step 1.
Would you prefer to stop loading Genesis 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. 🙂