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
Add a comment  | 

1 Answer 1

Reset to default 0

If 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