Create a Custom Block Category in the WordPress Block Inserter (Gutenberg)

Create a Custom Block Category in the WordPress Block Inserter (Gutenberg)

Matt Watson's photo
Matt Watson
·Mar 19, 2021·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

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(
                '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 InserterCustom 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.

Share this


© Wholesome Code Ltd. (Business No: 12196107) All rights reserved.