WordPress: tips and tricks disable specific Gutenberg blocks
Since WordPress 5.x we got introduced to the Gutenberg editor. Most of the times, you want to have your customer full access, to every block that is available with Gutenberg.
Once you opened up the sidebar, you can view a lot of block types. That are probably never going to be used.
But in some situations you prefer disabling, specific blocks from Gutenberg.
Media files
By my own personal experience, depending on the use-case you want for example to disable the video or the audio block.
I encountered costumers uploading huge amounts of uncompressed video files. Resulting in reaching the maximum storage limit of a shared hosting company.
Customers who upload a lot:
- Try pushing that customer in uploading to Vimeo, Youtube or Odysee
- For audio use SoundCloud instead
There is no design
Your WordPress theme you’ve developed, looks wonderful but simply doesn’t has a design for the RSS-feed, categories, or calendar.
By experience, you want to disable some blocks that have no design, to avoid emailing afterwards about some element that looks weird and want is styled for free.
Solution
You can add the following code in your functions.php, by writing a hook and only return the ones you want to keep.
If you aren’t interested in coding, you can always download the plugin Disable Gutenberg Blocks — Block Manager. But if you prefer keeping your WordPress website more lightweight, I do recommend programming it yourself.
Tip: debug what is available
If you want to see which blocks are available, you can always var_dump the variable $original_blocks.
<?phpfunction custom_allowed_block_types($original_blocks){
var_dump($original_blocks);
exit;
// Output:
array(4) { [0]=> string(xx) "core/list" [0]=> string(xx) "core/heading" }
}
Tip: disable blocks by role
In some cases you want to disable a block, for specific role.
Other
If you are interested, you can also read about customizing Gutenberg blocks into Bootstrap without JavaScript. Or disable WP Cron in your WP-json REST namespace.
Resources
You can find the full list at: