I'm trying to unregister core block types in WordPress Gutenberg.

I've used the code provided here: https://github.com/WordPress/gutenberg/blob/master/docs/extensibility/extending-blocks.md#removing-blocks

But I can't get it to work. I feel like there may be a simple step I am missing?

  1. I created a plugin which I activated in my WP theme.
  2. In my plugin [clore-blocks] folder I created "clore-blocks.php". It contains:
/**
 * Remove certain blocks.
 */
function clore_blacklist_blocks() {
    wp_enqueue_script(
        'clore-blacklist-blocks',
        plugins_url( 'blocks.js', __FILE__ ),
        array( 'wp-blocks' ),
        filemtime( plugin_dir_path( __FILE__ ) . 'blocks.js' ) // Version: filemtime - Gets file modification time.
    );
}
add_action( 'enqueue_block_editor_assets', 'clore_blacklist_blocks' );
  1. In blocks.js I have only:
wp.blocks.unregisterBlockType( 'core/verse' );

I thought this would remove the "Verse" block type from being used, but when I go to edit a page with the Gutenberg editor, "Verse" is still there.

When I view the page source from the WP edit page, I can see that my "blocks.js" file is being referenced correctly, but It's just not doing anything... or at least not what I want it to do. Do you have any idea why that is?

  • 1
    What do you mean by "a plugin which I activated in my WP theme?" Is your code a plugin, or a theme? – WebElaine Aug 3 at 19:49
  • My code is written as it's own little plugin. – LKD Aug 6 at 14:05
  • I am having the same issue. When I do wp.blocks.unregisterBlockType( 'core/verse' ) (or any other core block type) I get an error in the console that this block type is not registered. – JakeParis Nov 13 at 16:13

Everything works for me with allowed_block_types hook.

Example:

add_filter( 'allowed_block_types', 'my_function' );

function my_function( $allowed_block_types ) {

    return array(
        'core/paragraph'
    );

}

You can insert the above code to your functions.php file to a custom plugin. It removes all blocks except the Paragraph block.

More examples here https://rudrastyh.com/gutenberg/remove-default-blocks.html

  • This is not always a good solution because it removes all blocks except for a whitelist. – JakeParis Nov 13 at 16:11

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.