WordPress Gutenberg blocks: How to restrict page-level blocks, but allow all child-level blocks WordPress Gutenberg blocks: How to restrict page-level blocks, but allow all child-level blocks wordpress wordpress

WordPress Gutenberg blocks: How to restrict page-level blocks, but allow all child-level blocks


Crossposted from my answer on WordPress StackExchange

The short answer is you can’t. But you can accomplish this by using a block template that only contains your block and is locked. If your block has an InnerBlocks instance, you can add any of the registered blocks to it.

add_action( 'init', 'insert_template' );function insert_template() {    $post_type_object = get_post_type_object( 'post' );    $post_type_object->template =[ [ 'your-custom-block-name'] ];    $post_type_object->template_lock = 'all';}