Gutenberg: The block must have a registered category

Created on 4 Jan 2019  路  12Comments  路  Source: WordPress/gutenberg

Hello,

I created custom block categories as mentioned here: https://wordpress.org/gutenberg/handbook/designers-developers/developers/filters/block-filters/#managing-block-categories

and I get the following console error:
The block must have a registered category.

However, the categories work great and I can see my blocks there.

I create the custom categories before creating the blocks. Does anyone have any suggestion on how to fix it?

Thanks in advance.

[Feature] Block API [Status] Needs More Info [Type] Help Request

Most helpful comment

@swissspidy I had to call my block's JS file using:

add_action('enqueue_block_editor_assets', 'my_block_function');

instead of:

add_action('init', 'my_block_function');

as mentioned here: https://wordpress.org/gutenberg/handbook/designers-developers/developers/tutorials/block-tutorial/writing-your-first-block-type/

All 12 comments

@swissspidy @youknowriad Is there any solution for this problem?

Can you share your code? (filter and block)

and can you call wp.blocks.getCategories() in the console and see the results?

Hello,

wp.blocks.getCategories() returns default categories + my custom categories.

The code is:

function jtec_block_categories( $categories, $post ) {
    return array_merge(
        $categories,
        array(
            array(
                'slug' => 'my-category',
                'title' => __( 'My Category', 'jt-event-calendar' ),
            ),
        )
    );
}
add_filter( 'block_categories', 'jtec_block_categories', 10, 2 );

Thanks in advance!

What about your block's code? I don't have any explanation aside:

  • you have a typo
  • The message is coming from another block

@youknowriad I don't get any error and the blocks work great. This console error appears for all of my custom blocks that have as category "my-category" (based on the code of the previous comment).

I think I found the problem. This issue can be closed now.

What was the issue @izachros?

@swissspidy I had to call my block's JS file using:

add_action('enqueue_block_editor_assets', 'my_block_function');

instead of:

add_action('init', 'my_block_function');

as mentioned here: https://wordpress.org/gutenberg/handbook/designers-developers/developers/tutorials/block-tutorial/writing-your-first-block-type/

@swissspidy I had to call my block's JS file using:

add_action('enqueue_block_editor_assets', 'my_block_function');

instead of:

add_action('init', 'my_block_function');

as mentioned here: https://wordpress.org/gutenberg/handbook/designers-developers/developers/tutorials/block-tutorial/writing-your-first-block-type/

This helped me fix an identical issue with my block plugin. Thanks!

@swissspidy I tried the method you suggested but I'm still getting the same error.

@mteera I did not suggest anything 馃 If you encounter problems, please open a new issue with detailed information. Try support forums first too.

@izachros's reply above - https://github.com/WordPress/gutenberg/issues/13182#issuecomment-453851661 - helped me as well. I had read through tons of documentation in the Block Editor Handbook and various tutorials, but I kept seeing the init hook used to enqueue the javascript file that registers a custom block, the enqueue_block_editor_assets is not mentioned as the appropriate hook to use. What is the main difference between the two hooks with regards to registering custom blocks?

Was this page helpful?
0 / 5 - 0 ratings