Removing Default Gutenberg Blocks

In this tutorial I will show you a super-simple way to remove any of the default Gutenberg blocks from the inserter.

#Gutenberg, #wp-admin  /    /   27

Well, Gutenberg is going to be a part of WordPress сore really soon and I decided to move my whole website experience to the Gutenberg editor ⚑️😁

Once I installed Gutenberg I faced with some issues.

  • White screen on the page/post edit pages, which was resolved just by switching the theme to default and back again.
  • Console errors, all of them has been fixed when I removed this code from the functions.php which disables the REST API.

And the next thing I faced with is the large amount of blocks, which is cool of course, but I’m such a minimalist.

How to remove unneeded Gutenberg default blocks
Well, I absolutely don’t need so much Embeds (34) on my website 😁

How to Remove Certain Default Blocks from the Inserter? #

In fact, I didn’t find a way to remove specific blocks from the inserter with the help of hooks (so, we can use them in the current theme functions.php file or in a custom plugin). But there is an awesome hook allowed_block_types that allows to specify blocks we would like to use on our website and besides it accepts $post parameter, so we can use different blocks for different post types and that’s awesome!

Example, on my website I would like to use only Paragraph, Heading, Image and List blocks, for any post types, in that case my code will look like:

add_filter( 'allowed_block_types', 'misha_allowed_block_types' );
 
function misha_allowed_block_types( $allowed_blocks ) {
 
	return array(
		'core/image',
		'core/paragraph',
		'core/heading',
		'core/list'
	);
 
}

If you tried to print_r( $allowed_blocks ), it returns nothing. Why? Because by default the allowed blocks array is empty, which means to display all blocks. If we add something to this array, only the blocks from the array will be displayed.

If allowed_block_types filter hook is used several times on your website, you could get or print the allowed blocks array which was specified earlier in the same hook.

Maybe you’re wondering where to get block IDs (slugs) to pass into the array. The full list is below.

And here is my result:

Allowed Gutenberg blocks specified with allowed_block_types filter hook.
So clean! I love it πŸ–€

Allow/Disallow Certain Blocks for Specific Post Types #

Do you remember, I mentioned that allowed_block_types hook accepts $post parameter? Let’s use it now! For example, we will add one more block – Shortcode for Pages. In this case our code will be changed a little bit:

add_filter( 'allowed_block_types', 'misha_allowed_block_types', 10, 2 );
 
function misha_allowed_block_types( $allowed_blocks, $post ) {
 
	$allowed_blocks = array(
		'core/image',
		'core/paragraph',
		'core/heading',
		'core/list'
	);
 
	if( $post->post_type === 'page' ) {
		$allowed_blocks[] = 'core/shortcode';
	}
 
	return $allowed_blocks;
 
}

What is $post? Post object indeed! So, you can even allow or disallow specific blocks by the post ID!

Here is my result for Pages:

List of block slugs #

To make it more clear, I split the list by categories and added some screenshots.

1. Common blocks category

Common blocks from the inserter
  • core/paragraph
  • core/image
  • core/heading
  • (Deprecated) core/subhead — Subheading
  • core/gallery
  • core/list
  • core/quote
  • core/audio
  • core/cover-image
  • core/file
  • core/video

2. Formatting category

Default Gutenberg blocks from the Formatting category
  • core/table
  • core/verse
  • core/code
  • core/freeform — Classic
  • core/html — Custom HTML
  • core/preformatted
  • core/pullquote

3. Layout Elements category

Layout Elements Gutenberg blocks
  • core/button
  • core/text-columns — Columns
  • core/media-text — Media and Text
  • core/more
  • core/nextpage — Page break
  • core/separator
  • core/spacer

4. Widgets category

Widgets blocks category
  • core/shortcode
  • core/archives
  • core/categories
  • core/latest-comments
  • core/latest-posts

5. Embeds category

Embeds blocks category

Oh my gosh, so much blocks are here.

  • 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

Now my Gutenberg inserter is so clean and I’m happy to work with it. Of course I will create some custom blocks for my needs there, but it is the topic of a new tutorial. πŸ™ƒ

Misha Rudrastyh
About the author Misha Rudrastyh

Passionate about WordPress and snowboarding, creating websites for over 10 years! Let's work together — just contact me.

If you are a developer too, subscribe to my facebook page.

Comments 27

Newer →
  • Good to know we can disable or “enable” them as needed :) I was already a bit scared when thinking about the next WordPress themes to build for customers having all the core blocks by default and thought about how to get all that block elements styled fitting to the rest of the theme.

    Thanks for posting this tutorial – it’s very helpful!

  • perfect. Thank you indeed. Very useful!

    Personally, when I first explored Gutenberg 6 months or so back I thought, “okay this is cool.”

    While it is playing “catchup” to other website builders and applications out there, it’s still way better.

    But then I explored it again…. and I thought, “okay, still cool for some, but way too much for others. It’s a solid foundation, but I’m already to strip it down quuuuite a bit.”

    So cheers!

  • Will this deregister all blocks from plugins as well?

  • Hey this is very useful and something I was looking for to build the next custom themes. Thanks so much!

  • How do you include a custom block in the $allowed_blocks array?

    Say I have a custom block named “custom-testimonial”. I tried the following and none seem to work:

    ‘core/custom-testimonial’
    ‘custom/custom-testimonial’
    ‘custom-testimonial’

    Do you know what code will correctly include the custom block in the array so it is still included in the editor?

    • Hey Taylor,

      You just have to find out how your custom block is registered, example:

      wp.blocks.registerBlockType( 'misha/custom-testimonial', {
      	title: 'Custom block',
      	icon: '...

      So, in the above example it will be misha/custom-testimonial. Just pass it into the $allowed_blocks array as well.

  • Looks like you can also get all registered blocks with:

    WP_Block_Type_Registry::get_instance()->get_all_registered()

    In case you want to filter out just some of them (blacklist vs whitelist).

  • Thanks for the article.

    Just a headup: `core/text-columns` seems to have been renamed to `core/columns`.

    Also, using this filter seems to prevent any reusable block to be used. Has anyone find a solution?

  • Ok, got it, had to add `’core/block’` to the allowed block list.

  • Hi,

    Just spotted this blacklist option

    https://wordpress.org/gutenberg/handbook/extensibility/extending-blocks/#using-a-blacklist

    So you can just remove one block at a time, if that’s you’d rather than enable.

    Thanks for the post!

  • Joseph Dickson

    Thanks Misha,

    I couldn’t get blacklist and whitelist to work so this helped.
    I also couldn’t find official documentation for the core slugs. Do you know if there’s an official list in the Gutenberg Handbook on wordpress.org?

Leave your question or feedback

phpjsHTMLCSSSQLCode
Please, enter a comment
Please, enter a name
Incorrect email