Menu

How to add custom categories to Gutenberg

Gutenberg Custom Category

To add a custom category for your Gutenberg blocks add the following PHP code to your plugin, then add a block to your new category. The category won’t show until you add a block.

<?php
/**
 * Custom block category
 */

function my_blocks_plugin_block_categories( $categories ) {
    return array_merge(
        $categories,
        array(
            array(
                'slug' => 'my_category',
                'title' => __( 'My Custom Category', 'mydomain' ),
                'icon'  => 'wordpress',
            ),
        )
    );
}
add_filter( 'block_categories', 'my_blocks_plugin_block_categories', 10, 2 );