I've created a custom top level "page section" block, to work with my existing theme. I've like to restrict top level blocks to ONLY that one block. However, I don't want to disable all blocks completely, because I want all blocks available to use as innerBlocks.


How can I restrict top level blocks, without restricting child level blocks?

2 Answers 2


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';
  • I did a quick search and that may be exactly what I need. I'll investigate it further today.
    – Kelderic
    Commented Nov 30, 2019 at 17:31
  • 1
    I’ll try and get some code samples together and update my answer.
    – Welcher
    Commented Nov 30, 2019 at 17:32
  • I added a bounty to this same question over on StackOverflow. If you'd like to post this answer there, I'll give you the bounty. stackoverflow.com/q/55962177/2111901
    – Kelderic
    Commented Dec 4, 2019 at 3:08
  • And I think what I need is two levels. A custom block called page body, or something, that is called in the template and locked. Then that has an innerBlocks locked to only my page section blocks, but unlimited. Thanks!
    – Kelderic
    Commented Dec 4, 2019 at 3:10
  • Glad to help! I posted to the bounty as well
    – Welcher
    Commented Dec 4, 2019 at 4:07

You can add a custom script to the admin panel using the admin_enqueue_scripts action.

Here is an example of how you can restrict existing blocks to only be included inside certain blocks:

const restrictEditorParentBlocks = (settings, name) => {
    const TEXT_EDITOR_BLOCKS = [

    if (TEXT_EDITOR_BLOCKS.includes(name)) {
        settings.parent = ['example/my-custom-block-that-needs-text-editor-blocks']

    console.log(settings, name)

    return settings


This will disable them for the page, but allow them inside the specified parent blocks.

(see settings.parent assignment)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.