3

I've restricted a number of the default core Gutenberg blocks as many are unnecessary for my clients and will just add to the confusion of having the new editor.

The result of this is some core categories just have a single block inside them e.g. "formatting" only has a table.

Is it possible to edit/remove core block categories and move all blocks under a single category??

Limiting my blocks;

add_filter( 'allowed_block_types', 'res_allowed_block_types' );
function res_allowed_block_types( $allowed_blocks ) {
    return array(
        'core/image',
        'core/paragraph',
        'core/heading',
        'core/list',
        'core/quote',
        'core/cover-image',
        'core/file',
        'core/video',
        'core/table',
        'core/separator',
    );
}

1 Answer 1

4

Although I'm unsure on how to achieve this in php, within javascript you can change the category by hooking into the blocks.registerBlockType hook.

Here is a small example how it would work, although I'd recommend using lodash to deepClone the settings object to keep everything immutable.

const rearrangeBlockCategories = {
  'core/table': 'common',
};

wp.hooks.addFilter('blocks.registerBlockType', '[namespace]', (settings, name) => {
  if (rearrangeBlockCategories[name]) {
    settings.category = rearrangeBlockCategories[name];  
  }

  return settings;

});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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