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.

/46 comments

Well, I published this tutorial when Gutenberg was going to be a part of WordPress сore and I decided to move my whole website experience to the Gutenberg editor. Gutenberg UI has been changed two times since then, so I updated this tutorial to the latest version.

Once I installed Gutenberg the first time I faced with some issues.

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

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 (33) 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:

How to remove unneeded Gutenberg default blocks
So clean! I love it πŸ–€

If you want to keep any later installed plugins blocks, I highly recommend to check this comment thread.

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:

Turn on or turn off certain Gutenberg blocks for a specific post type

List of Gutenberg block slugs

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

1. Common blocks category

Common blocks from the inserter

2. Formatting category

Default Gutenberg blocks from the Formatting category

3. Layout Elements category

Layout Elements Gutenberg blocks

4. Widgets category

Widgets blocks category

5. Embeds category

Embeds blocks category

Oh my gosh, so much blocks are here.

Block Manager – Turn off Gutenberg Blocks You Don’t Need Without a Single Line of Code!

A bonus for you πŸŽ‰

This feature was introduced in WordPress 5.2, so if you have 5.2 or a newer version installed probably you do not have to deal with all the code above.

Gutenberg block management feature in WordPress 5.2 and above

But. If you develop a custom theme and it shouldn’t support a certain block, of course, you have to deactivate it in the code.

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 πŸ™ƒ

More Gutenberg stuff

Misha Rudrastyh

Misha Rudrastyh

I love WordPress, WooCommerce and Gutenberg so much. 10 yrs of experience.

Need some custom developer help? Let me know

Follow Misha

Need some help with Gutenberg?

If you need some professional developer help, I will be happy to assist you.

Contact me Who I am?

Comments — 46

Leave a comment

php js HTML CSS Code

I will only use your personal information to contact you. Privacy Policy