Key points:
- Block templates allow you to define the structure of posts, which loads when you open the editor.
- This makes the structure easier to enforce and less prone to human error, especially if the template stays locked.
- With Advanced Custom Fields (ACF®), you can connect these templates to custom post types or use custom blocks.
When every page on a WordPress site is built from scratch, content creation becomes slow, messy, and inconsistent. Design errors creep in, and teams waste time repeating the same layout work.
WordPress block templates solve this by enforcing structure. They standardize how content is presented, reduce manual effort, and ensure a consistent look across the site.
But rigid templates aren’t enough. As design needs evolve, developers need systems that are both efficient and adaptable.
We will explore how to build customizable block templates in WordPress – templates that save time while giving developers the flexibility to tweak layouts, update components, and keep design systems responsive to change.
What are block templates in WordPress?
Block templates in WordPress define the default layout and pre-populated blocks for specific post types or pages.
When a user creates a new post or page, the block template automatically loads a predefined structure – think headings, images, text areas, or calls to action – ensuring consistency across content and reducing the need to build layouts from scratch every time.
Block templates are often confused with block patterns, but they differ in key ways:
Block templates | Block patterns | |
Usage | Automatically applied to specific post types or pages. | Manually inserted into content by the user. |
Purpose | Define the default structure for consistent content layout. | Provide reusable design components. |
Editing control | Can restrict or lock block editing to maintain structure. | Fully editable once inserted, with no structural controls. |
Consistency | Enforces standardization across content types. | Prone to inconsistency if overused or edited freely. |
It’s also easy to get them mixed up with theme templates, but there are some critical differentiators:
Block templates | Theme templates | |
Scope | Define default block layouts for specific post types/pages. | Control the overall page structure (headers, footers, etc.). |
Granularity | Target individual pieces of content (e.g., a blog post). | Apply to entire sections or page types site-wide. |
Flexibility | Allow block-level customization, with optional block locking. | Often rigid; customization usually requires code changes. |
Real-world use cases for WordPress block templates
- Online magazines can have article templates with locked positions for headlines, featured images, and author bios.
- Real estate websites can use them for property listing templates with pricing, images, features, and agent contact details.
- eCommerce product pages can have pricing, product images, and add-to-cart buttons in a template.
- Event websites can use them to build event announcement pages with date/time blocks, maps, registration forms, and social sharing links.
- Portfolio sites can create project showcase layouts with image galleries, client testimonials, and project descriptions.
How to create WordPress block templates
Now that you’re familiar with the concept, it’s time to roll those sleeves up and start building your first WordPress block template.
We’ll start with the basics, then cover advanced custom block template techniques later in this guide. We’re going to be using PHP here and won’t cover the alternative JavaScript method, because, in practice, its functionality is closer to block patterns.
We recommend creating a custom plugin to handle this functionality instead of editing your child theme’s functions.php file. This way, your block stays active even if you switch to a different theme. It also makes it easier to export the block templates and use them on other sites.
When you’re ready to start, just follow these steps:
- In wp-content/plugins/ create a new folder for your custom block template. You can name it whatever you want.
- In this folder, create a PHP file, ideally with the same name as the folder, and add the following code to it to create a custom plugin with the desired functionality:
<?php
/**
* Plugin Name: Custom Block Template
* Description: Adds a default block template (title, paragraph, image, paragraph) to posts.
*/
function cbt_register_post_block_template() {
$post_type_object = get_post_type_object('post');
if ( $post_type_object ) {
$post_type_object->template = [
['core/heading', ['level' => 1, 'placeholder' => 'Enter title...']],
['core/paragraph', ['placeholder' => 'Write an intro paragraph...']],
['core/image'],
['core/paragraph', ['placeholder' => 'Write conclusion...']],
];
}
}
add_action('init', 'cbt_register_post_block_template');
- From your admin dashboard, go to Plugins > Installed Plugins and activate the template.
- From the dashboard, go to Posts > Add New Post, and it should load up with the template already applied.
Building advanced WordPress block templates
Building a simple block template is straightforward enough; the real excitement is with advanced templates, which let you take full control of your content workflow and look.
Building block templates for custom post types
You can assign a block template to a custom post type, which allows you to create distinction between the different kinds of content you produce.
Advanced Custom Fields (ACF®) allows you to spin up custom post types from a beginner-friendly UI, which is ideal for large-scale content production teams.
With your custom post type ready, all you need to do to assign a template to it is to specify it in the post_type_object
area of the code registering the template, i.e.:
$post_type_object = get_post_type_object( 'your_CPT_name' );
Building block templates with ACF Blocks
If you’re looking for more than what WordPress’s built-in blocks offer, you can use ACF Blocks to create your own.
To use this block in a template, insert it by referencing it like you would a native block, but change core
to acf
in the code, i.e., acf/your-custom-block
.
For example, if we wanted to use a custom block from our detailed walkthrough in the sample from the section above, we’d need to use to reference it.
Here’s what the custom block looks like by itself:
Here’s what the code would look like, with only one new line:
<?php
/**
* Plugin Name: Custom Block Template
* Description: Adds a default block template (title, paragraph, image, paragraph) to posts.
*/
function cbt_register_post_block_template() {
$post_type_object = get_post_type_object('post');
if ( $post_type_object ) {
$post_type_object->template = [
['core/heading', ['level' => 1, 'placeholder' => 'Enter title...']],
['core/paragraph', ['placeholder' => 'Write an intro paragraph...']],
['acf/my-custom-block'],
['core/image'],
['core/paragraph', ['placeholder' => 'Write conclusion...']],
];
}
}
add_action('init', 'cbt_register_post_block_template');
And here’s the template in the editor:
Supercharge Your Website With Premium Features Using ACF PRO
Speed up your workflow and unlock features to better develop websites using ACF Blocks and Options Pages, with the Flexible Content, Repeater, Clone, Gallery Fields & More.
Locking WordPress block templates
Block templates are meant to standardize content, but that all falls apart when anyone with access to the editor can change the layout if they feel like it.
Luckily, you can lock your block templates by adding the following line of code right above the function’s closing curly brace:
$post_type_object->template_lock = 'all';
Setting it to all
prevents users from adding, moving, or deleting blocks in the template. For more flexibility, you can change it to insert
to allow users to move the existing blocks around while preventing them from adding or removing blocks.
Applying the same lock for all users isn’t always practical, though. For instance, you’d want stricter controls on an intern than an editor-in-chief.
Here, you can use conditional logic to verify the user’s role and apply rules accordingly. Just add an if
statement before specifying the lock rules, e.g.:
if ( ! current_user_can('administrator') ) {
$post_type_object->template_lock = 'all';
}
This code checks if the current user is an admin and, if they’re not, it applies the template lock.
For more granular control and to lock an individual block, add the attributes inline, e.g.:
['core/image', [
'lock' => [
'move' => true
'remove' => true
]
]]
Best practices for working with block templates in WordPress
- Lock only the most critical blocks to balance consistency and flexibility. Locking everything down can frustrate content editors, while locking just the essential elements – like headers or featured media – helps preserve layout integrity without making the editing experience rigid.
- Use placeholder content to guide users toward accurate and consistent content entry. Well-placed examples or prompts within text and media blocks reduce confusion, minimize formatting errors, and create a smoother workflow for teams with multiple contributors.
- Define block attributes precisely to maintain visual consistency across your site. Setting exact image sizes, alignments, and spacing ensures that templates behave predictably, reduces manual styling work, and prevents design drift as content changes.
- Separate recurring sections into reusable template parts to simplify the main template structure. Do this with headers, footers, and bylines to make future updates easier, since changes to a single template part can propagate across multiple templates instantly.
Standardize your content with block templates and ACF PRO
Block templates let you define exactly how posts are structured from the start, giving you full control over layout and consistency.
Unlike block patterns, they don’t rely on users manually inserting design elements – templates load automatically with every new post or page. Compared to theme templates, they offer a more flexible, content-focused approach without sacrificing structure.
When paired with ACF PRO, block templates become even more powerful. You can assign them to custom post types and integrate custom ACF Blocks to create a tailored editing experience that scales with your content needs.
From speeding up simple content creation to managing complex publishing workflows, block templates give you the control and efficiency to make it happen.
If you’re ready to build smarter, more flexible WordPress templates, explore ACF PRO and start customizing with precision.
For plugin support, please contact our support team directly, as comments aren't actively monitored.