🧱 Gutenberg Blocks

Restricting to Post Types

Limit blocks for usage within specific post types

You can restrict an individual block type to only be used in certain post types.

To do this, just update your block's Types property. You can have multiple types, separated by commas.

/*
 * ...
 * Types: page, post
 * ...
 */

Template Locking

Taking this a step further, you can also specify required root blocks for a post type.

For example, you might want to specify that when creating a new blog post, that only 'Blog Post Header' and 'Blog Post Content' blocks are added to root, and are automatically added when creating a new post, and also cannot be removed.

This needs to be done in PHP:

backend/blocks.php
<?php

  ED()->templateLock([
    'type' => 'post',
    'content' => [
      ['acf/blog-post-header'],
      ['acf/blog-post-content'],
    ]
  ]);

⚠️

Note that you need to use the internal ACF block name when working with template locks. For example, blog/post-header becomes acf/blog-post-header.