How to remove unwanted WordPress Gutenberg blocks

The WordPress Gutenberg editor comes with over 30 editor blocks. The blocks allow editors to change column layout, add buttons, embed Tiktoks and much more.

Most blocks will never get used. I wanted a way to limit which blocks were available to editors so they only see the ones they need to see. 

How to create an allowed block type list

Add the following script to your function.php file. This will allow you to list which blocks appear within the editor of your WordPress theme.

<?php
add_filter( 'allowed_block_types_all', 'theme_allowed_block_types' );
 
function theme_allowed_block_types( $allowed_blocks ) {
 
	return array(
		'core/paragraph',
		'core/heading',
	);
 
}
?>

This function will only allow 2 block types – paragraphs and headings. However, you can easily adapt this by adding the block types you want to use. Each block type has its own block slug. For example the block type for adding audio files has a slug ‘core/audio’. You can find a list of block type slugs below.

List of WordPress blocks by slug / namespace

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

Find what each block does on the WordPress website.

Setup problems

There were a couple of issues I found trying to remove unwanted blocks.

The first is the block called ‘core/embed’. This block allows editors to embed lots of different things such as videos from Youtube or songs from Spotify. The issue with this block is you can’t limit which embeds you want editors to use with the method I’ve described above. There is a discussion about the issue on StackExchange.

The other issue is finding a block name. Many plugins have blocks you can use. For example I use a plugin called Syntaxhighlighter. Its block name is called ‘syntaxhighlighter/code’ but finding the block name was hard.

Tags

Leave a comment