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

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
  • 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/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 9 years! Let's work together — just contact me.

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

Comments 20

← Older
  • 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?

  • 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?

Leave your question or feedback

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