As we know by the provided API from Gutenberg we can create a custom block as

const { registerBlockType } = wp.blocks;

registerBlockType( 'my-namespace/my-block', {

})

but how do I create a wrapper(category like layout) around my custom blocks in gutenberg editor?
Let’s say I want to have a collector for my custom elements as slider, gallery …

2 s
2

Digging myself deeper in documentation, I got the following result.

There is a way to group your custom blocks around a given category in Gutenberg, and therefore we have the method block_categories_all. So with a filter, you can extend the default categories with custom ones.

Here is my example:

add_filter( 'block_categories_all', function( $categories, $post ) {
    return array_merge(
        $categories,
        array(
            array(
                'slug'  => 'my-slug',
                'title' => 'my-title',
            ),
        )
    );
}, 10, 2 );

You can find more on this in the provided API.

Leave a Reply

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