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  /    /   31

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 (previously 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 31

← Older
  • For those that are using the `acf_register_block` method, you will need to use the prefix of `acf/your_custom_block_name_here`.

    • Also, found another quirk, if you use `’name’ => ‘your_custom_block_name_here’` when registering, you will need to replace underscores as hyphens.

  • Thanks a bunch for this tutorial! I also noticed that if you’re inside the paragraph block and you click on the add block icon it shows an “Inline Elements” tab with “Inline Image” block inside of it.
    How would you remove that?

  • ‘core/media-text’ is missing from Layout Elements here. This is so strange to have to define ALL that you want when you want to exclude certain blocks.

  • I follow your tutorial and was able to successfully remove the default Gutenberg blocks. I am creating new blocks using ACF and am trying to add reusable blocks back to the editor. And ideas on how to do this? Thanks!

    • Hey Logan,

      ACF seems a good plugin but I do not like it and never use it on my projects.

      • Sorry I think I said that wrong. Yes I am using ACF to create new blocks, BUT I do not think the issue is because of ACF. When I follow your tutorial and limit blocks based on post type I lose the option to make them reusable blocks. My question is do you know how to add that option back after limiting what blocks can be used by custom post types?

        • Yeah – this is one of things that stops this being 100%

          I found these block IDs to add:

          // — Reusable
          ‘core/block’,
          ‘core/template’,

          …but reusable blocks remain disabled – any ideas Misha?

    • The following worked for me. I use “hero” as an example block name, but you can of course use your own.

      – in acf_register_block: 'name' => 'hero'

      – in the allowed_block_types filter function: return array( 'acf/hero' );

  • Well, I was looking for a way to remove a certain block from the editing page (I’m new to Gutenberg), and this post is definitely not what I was looking for. Oh well, moving on.

  • This was very helpful, thanks! As a non-developer type who doesn’t want to dig too far into the code is there any chance you (or someone else) might build a helpful plugin that allows you to “hide” all the block types you don’t want users to see? The amount of choices is really overwhelming when I am teaching clients how to use Gutenberg editor. I really only want to give them like 5-8 block choices.

  • Using `core/cover-image` doesn’t display the cover image block, has it been renamed?

  • Non-developers can use this plugin – https://wordpress.org/plugins/disable-gutenberg-blocks/

Leave your question or feedback

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