Hack: Limit Which Blocks Writers Can Use

Depending on what type of site you have, some of the blocks available are never going to be used. You can limit your writers to just a few blocks pretty easily with code like this in your functions.php or custom plugin.

add_filter('allowed_block_types', 'wpfilter_allowed_block_types');
function wpfilter_allowed_block_types() {
	$allowed_block_types = ['core/paragraph', 'core/image', 'core/heading'];
	return $allowed_block_types;
}

What’s frustrating is that it would be nice to get the full list of blocks and then unset items in the list to get rid of a few. But the allowed_block_types filter doesn’t pass them in, only an empty array signifying “all.” So you have to build your own list.

Getting the names to put in the list is tough too. Looks like just making them lowercase and removing spaces works, more-or-less. But you have to know things like Hulu is core-embed/hulu and so on. I can’t find an official list, but some people have extracted a list and there are posts you can find.

Leave a Reply

Your email address will not be published. Required fields are marked *