admin管理员组文章数量:1122832
I've been trying to figure out if it's possible to restrict the innerblocks available in some of the core block. Right now I'm looking to restrict what can be used inside core/media-text and core/column. I have yet found a way to do this.
Before I plan on building out custom version of my own I thought I would ask and see if anyone knows of a way to do this that I haven't come across yet. I'd prefer to use the core block if possible.
I've been trying to figure out if it's possible to restrict the innerblocks available in some of the core block. Right now I'm looking to restrict what can be used inside core/media-text and core/column. I have yet found a way to do this.
Before I plan on building out custom version of my own I thought I would ask and see if anyone knows of a way to do this that I haven't come across yet. I'd prefer to use the core block if possible.
Share Improve this question edited Mar 20, 2023 at 17:02 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Mar 20, 2023 at 15:45 TidusInAtlantisTidusInAtlantis 311 bronze badge 7 | Show 2 more comments2 Answers
Reset to default 2Like TidusInAtlantis pointed out with the GitHub PR reference, it is possible to use block filters. Here is an example of how to restict the blocks allowed in core/columns.
import { addFilter } from '@wordpress/hooks';
addFilter('blocks.registerBlockType', 'your/namespace', function (settings, name) {
if (name !== 'core/column') {
return settings;
}
return {
...settings,
attributes: {
...settings.attributes,
allowedBlocks: {
type: 'array',
default: [
'core/paragraph',
'core/image',
'core/heading',
'core/separator',
'core/buttons',
],
},
},
};
});
For anyone looking for something similar I came across this in a PR - https://github.com/WordPress/gutenberg/pull/31326#pullrequestreview-781388981
This filter setup has worked for any block that I've tried that has allowedBlocks set as an array in the block.json file.
本文标签: Restricting core block nested blocks
版权声明:本文标题:Restricting core block nested blocks 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309365a1933994.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
theme.json
goes a long way towards remedying these kinds of problems by defining the various layout options. Overriding something as fundamental as columns is likely to have big consequences if you don't update it on every release – Tom J Nowell ♦ Commented Mar 20, 2023 at 18:34