admin管理员组文章数量:1023204
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
1 Answer
Reset to default 4Although 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;
});
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
1 Answer
Reset to default 4Although 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;
});
本文标签: Gutenberg moving core blocks between categories
版权声明:本文标题:Gutenberg moving core blocks between categories 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745519445a2154246.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论