How to disable WordPress blocks (in the editor and by code)

Home » Blog » WordPress Development » How to disable WordPress blocks (in the editor and by code)

Do you want to disable some blocks in the Gutenberg editor?

There are two ways to do it. The first one will only disable it for you. The second one will disable it for everyone on your website. You might want to do it to restrict what your web development clients can do to their websites.

Method 1: The Gutenberg Preferences

The easiest way to disable a Gutenberg block is to use to the Gutenberg preferences menu.

First, log into your WordPress website and create a new post. This will take you to the Gutenberg editor. Now, click the three dots on the top right of the editor, and select the last menu item called Preferences:

Now, go to the Blocks section and uncheck any of the blocks you don’t want to use:

Warning: This will only disable the blocks for your account, and not for anyone else.

Method 2: Disable With PHP

To disable a Gutenberg block for everyone, you can use the allowed_block_types_all filter. This filter lets you customize an array of allowed blocks.

Here’s how it works:

function wpturbo_allowed_blocks($allowed_blocks) {
	return array(
		'core/paragraph'
	);
}
add_filter( 'allowed_block_types_all', 'wpturbo_allowed_blocks' );

In the above code, we are returning an array that contains only one block type called “core/paragraph”. This will disable all other blocks except “core/paragraph”.

If you want to disable a particular block, you can return the $allowed_blocks variable after removing your undesired blocks from it like this:

function wpturbo_allowed_blocks($allowed_blocks) {
	// Removes the gallery block from the allowed list.
	array_splice($allowed_blocks, array_search('core/gallery'), 1);
	return $allowed_blocks;
}
add_filter( 'allowed_block_types_all', 'wpturbo_allowed_blocks' );

TIP: To use this code, place it in a custom plugin. To generate a custom plugin quickly, use our Plugin Code Generator…

List of all available blocks:

  • core/paragraph
  • core/image
  • core/heading
  • core/gallery
  • core/list
  • core/quote
  • core/audio
  • core/cover
  • core/file
  • core/video
  • core/table
  • core/verse
  • core/code
  • core/freeform (Classic Editor)
  • core/html
  • core/preformatted
  • core/pullquote
  • core/buttons
  • core/text-columns
  • core/media-text
  • core/more
  • core/nextpage
  • core/separator
  • core/spacer
  • core/shortcode
  • core/archives
  • core/categories
  • core/latest-comments
  • core/latest-posts
  • core/calendar
  • core/rss
  • core/search
  • core/tag-cloud
  • core/embed
  • core-embed/twitter
  • core-embed/youtube
  • core-embed/facebook
  • core-embed/instagram
  • core-embed/wordpress
  • core-embed/soundcloud
  • core-embed/spotify
  • core-embed/flickr
  • core-embed/vimeo
  • core-embed/animoto
  • core-embed/cloudup
  • core-embed/collegehumor
  • core-embed/dailymotion
  • core-embed/funnyordie
  • core-embed/hulu
  • core-embed/imgur
  • core-embed/issuu
  • core-embed/kickstarter
  • core-embed/meetup-com
  • core-embed/mixcloud
  • core-embed/photobucket
  • core-embed/polldaddy
  • core-embed/reddit
  • core-embed/reverbnation
  • core-embed/screencast
  • core-embed/scribd
  • core-embed/slideshare
  • core-embed/smugmug
  • core-embed/speaker
  • core-embed/ted
  • core-embed/tumblr
  • core-embed/videopress
  • core-embed/wordpress-tv

Conclusion

Disabling a Gutenberg plugin is really easy and only takes a few lines of code. The code above is all you need to disable any Gutenberg block you don’t like!

2 responses to “How to disable WordPress blocks (in the editor and by code)”

  1. A Avatar
    A

    Hi,
    If I would like to disable the core blocks and keep another Gutenberg plugin blocks enabled? How would I do that? Can I use wildcards?

  2. Alex Avatar

    hi, how about asking WPTurbo Ai about this? It should find the answer 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Register an account to save your snippets or go Pro to get more features.