DEV Community

Zakaria Binsaifullah
Zakaria Binsaifullah

Posted on • Edited on

How to Create a Custom Category in Gutenberg Block Editor

There are a number of categories for Gutenberg blocks. Suppose you are developing your own blocks or you have a number of custom blocks. Now you need to keep them under a separate custom category. So, you need to create a custom category for your blocks.

<?php
function boilerplate_register_block_category( $categories, $post ) {
    return array_merge(
        array(
            array(
                'slug'  => 'boilerplate',
                    'title' => __( 'Boilerplate', 'boilerplate' ),
            ),
        ),
        $categories,
    );
}
add_filter( 'block_categories_all','boilerplate_register_block_category', 10, 2 );
Enter fullscreen mode Exit fullscreen mode

If you write the above codes, then go back to your page or post to work with the Gutenberg Block. Now you will find a custom category named My Custom Category.

Top comments (0)