Add Custom Category For Custom Gutenberg Blocks

Gutenberg block editor have revolutionized the way we add/edit post/page content. The block editor consists of some pre-defined blocks like heading, paragraph, image etc. Other than the default blocks, we can also create custom Gutenberg blocks as well. In this tutorial blog post, we will learn how to add custom category for custom Gutenberg block(s).

Add Custom Category For Custom Gutenberg Blocks
Add Custom Category For Custom Gutenberg Blocks

Following WordPress filter can be used inside the plugin file or theme’s function.php file to create custom category for custom gutenberg block(s).

/**
 * Custom blocks category - mycategory
 */

function mycategory_plugin_block_categories( $categories ) {
    return array_merge(
        $categories,
        array(
            array(
                'slug' => 'mycategory',
                'title' => __( 'My Category', 'codoblocks' ),
                'icon'  => '',
            ),
        )
    );
}
add_filter( 'block_categories', 'mycategory_plugin_block_categories', 10, 2 );

Leave a Comment