Are you writing a lot of WordPress block editor (Gutenberg) blocks for just one client? Wouldnt it be good to just group them all together?

Simple, just create a custom block category. In the PHP of your plugin just add the following:

function wholesomecode_wholesome_plugin_block_categories( $categories ) {
	return array_merge(
		$categories,
		[
			[
				'slug'  => 'wholesome-blocks',
				'title' => __( 'Wholesome Blocks', 'wholesome-boilerplate' ),
			],
		]
	);
}
add_action( 'block_categories', 'wholesomecode_wholesome_plugin_block_categories', 10, 2 );

This will register a custom block category in your block inserter.

Adjust the category argument of the registerBlockType function for your block, like so:

/**
 * Blocks are grouped into categories to help users browse and discover them.
 * The categories provided by core are `text`, `media`, `design`, `widgets`, and `embed`.
 */
category: 'wholesome-blocks',

And there we have it, your block will appear in your newly created block category.

Custom Block Category in the Block Inserter
Custom Block Category in the Block Inserter

If you would like more information about creating blocks with Gutenberg have a look at my create a plugin for WordPress Gutenberg guide, which covers this topic in more details.

Previous ArticleNext Article

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.