最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Gutenberg moving core blocks between categories

programmeradmin0浏览0评论

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',
    );
}

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',
    );
}
Share Improve this question edited May 6, 2019 at 15:29 Christine Cooper 8,8977 gold badges60 silver badges93 bronze badges asked Dec 7, 2018 at 10:28 SamXronnSamXronn 1951 gold badge3 silver badges18 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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;

});
发布评论

评论列表(0)

  1. 暂无评论