admin管理员组文章数量:1122846
I'm new to the world of Gutenberg blocks. A customer has a special need to restrict the allowed blocks that can be used inside core/column block. The editor should only be able to select a small part of the blocks that Wordpress provides to the user. Is there a way (e.g. hook or CSS code) where this can be achieved?
I'm new to the world of Gutenberg blocks. A customer has a special need to restrict the allowed blocks that can be used inside core/column block. The editor should only be able to select a small part of the blocks that Wordpress provides to the user. Is there a way (e.g. hook or CSS code) where this can be achieved?
Share Improve this question asked Apr 10, 2024 at 6:50 Acer82Acer82 1 1- developer.wordpress.org/news/2024/01/29/… I think this is a pretty common procedure the a lot of devs use when building blocks. – Tony Djukic Commented Apr 22, 2024 at 22:02
1 Answer
Reset to default 0If you're using WordPress 6.5+, then you can filter the column blocks settings and add allowedBlocks
array to it. In the array you'd define all the blocks, which the user can insert into the column.
wp.hooks.addFilter( 'blocks.registerBlockType', 'my-column-blocks', ( settings, name ) => {
if ( name === 'core/column' ) {
const { allowedBlocks = [] } = settings;
return { ...settings, allowedBlocks: [ ...allowedBlocks, 'core/paragraph' ] };
}
return settings;
} );
本文标签: Allowed blocks for corecolumn
版权声明:本文标题:Allowed blocks for corecolumn 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736310288a1934323.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论