What are Block Templates?
Templates allow you to:- Set default blocks: Pre-populate the editor with blocks
- Configure initial state: Set default attributes and content
- Lock structures: Prevent users from modifying the layout
- Guide content creation: Provide structure for specific content types
Template Scope
Templates can be applied at two levels:- Post Type Templates: Define default blocks for entire post types
- InnerBlocks Templates: Define default nested blocks within a container block
Post Type Templates
Define default blocks that appear when creating a new post of a specific type.Basic Post Type Template
Template with Attributes
Custom Post Type with Template
Template Locking
Control how users can modify the template structure.Lock Options
contentOnly- Only allows editing block content. Hides blocks without content from list view.all- Prevents all operations (insert, move, delete)insert- Prevents inserting/removing blocks (allows reordering)falseor not set - No locking (default)
Example with Locking
Nested Templates
Templates can include blocks with inner blocks:InnerBlocks Templates
Define default nested blocks for container blocks.Basic InnerBlocks Template
InnerBlocks Template with Locking
Individual Block Locking
Lock individual blocks within a template:JavaScript
PHP
remove- Lock/unlock removal of the blockmove- Lock/unlock moving the block
Template API Format
Templates are defined as arrays of block configurations:Block Attributes in Templates
Find available attributes in block.json files:Example: Heading Block
Complete Examples
Blog Post Template
Product Template
FAQ Template
Template Inheritance
InnerBlocks inherit locking from their parent:- If InnerBlocks
templateLockis not set, parent’s lock is used - If block is top-level, post type’s
template_lockis used - Explicit
templateLockalways takes precedence
Finding Block Attributes
To find available attributes for templates:In Gutenberg Plugin
Checkpackages/block-library/src/[block-name]/block.json
In WordPress Core
Checkwp-includes/blocks/[block-name]/block.json
Template vs Pattern vs Variation
| Feature | Template | Pattern | Variation |
|---|---|---|---|
| Scope | Post type / InnerBlocks | User-insertable | Single block |
| Locked | Can be locked | Never locked | N/A |
| Automatic | Appears automatically | User must insert | User must select |
| Purpose | Structure posts | Reusable layouts | Block configurations |
Best Practices
- Provide placeholders: Help users understand what content goes where
- Use appropriate locking: Balance structure with flexibility
- Test the workflow: Ensure the template improves the editing experience
- Document required fields: Make it clear what users must fill in
- Consider accessibility: Use semantic HTML and proper heading hierarchy
- Keep it simple: Don’t over-structure the content
- Allow some flexibility: Total locking can be frustrating
Common Use Cases
Landing Page Template
Recipe Template
Related Documentation
- InnerBlocks - Nested block component
- Block Patterns - Reusable layouts
- Block Variations - Block configurations
- Meta Box Tutorial - Using templates with meta boxes