Block Templates System
WordPress Block Templates (also known as FSE – Full Site Editing templates) are a fundamental part of block themes. They allow themes and plugins to define site structure using blocks stored as HTML files or in the database.
Template Types
wp_template
Full page templates that control the entire page layout. Stored in the theme’s templates/ directory (or legacy block-templates/).
Examples:
index.html– Fallback for all pagessingle.html– Single postspage.html– Static pagesarchive.html– Archive listings404.html– Not found pages
wp_template_part
Reusable template sections. Stored in the theme’s parts/ directory (or legacy block-template-parts/).
Examples:
header.html– Site headerfooter.html– Site footersidebar.html– Sidebar content
Template Hierarchy (Block Theme)
The block template hierarchy mirrors classic PHP templates but uses .html files with block markup:
front-page.html
├── home.html
│ └── index.html
│
single-{post-type}-{slug}.html
├── single-{post-type}.html
│ ├── single.html
│ │ ├── singular.html
│ │ │ └── index.html
│
page-{slug}.html
├── page-{id}.html
│ ├── page.html
│ │ ├── singular.html
│ │ │ └── index.html
│
archive.html
├── author-{nicename}.html
├── author-{id}.html
├── author.html
├── category-{slug}.html
├── category-{id}.html
├── category.html
├── tag-{slug}.html
├── tag-{id}.html
├── tag.html
├── taxonomy-{taxonomy}-{term}.html
├── taxonomy-{taxonomy}.html
├── taxonomy.html
└── date.html
└── index.html
search.html
└── index.html
404.html
└── index.html
Template Sources
Templates can come from multiple sources, listed by priority:
- Database (custom) – User-modified templates stored as
wp_templateposts - Theme files –
.htmlfiles in the theme’stemplates/directory - Parent theme files –
.htmlfiles in parent theme (for child themes) - Plugin-registered – Templates registered via
register_block_template()
Template Part Areas
Template parts are categorized by area using the wp_template_part_area taxonomy:
| Constant | Value | Description | HTML Tag |
|---|---|---|---|
WP_TEMPLATE_PART_AREA_HEADER |
header |
Site header | <header> |
WP_TEMPLATE_PART_AREA_FOOTER |
footer |
Site footer | <footer> |
WP_TEMPLATE_PART_AREA_SIDEBAR |
sidebar |
Sidebar | <aside> |
WP_TEMPLATE_PART_AREA_UNCATEGORIZED |
uncategorized |
General/other | <div> |
Theme Directory Structure
my-theme/
├── templates/ # Block templates (wp_template)
│ ├── index.html
│ ├── single.html
│ ├── page.html
│ └── archive.html
├── parts/ # Template parts (wp_template_part)
│ ├── header.html
│ ├── footer.html
│ └── sidebar.html
├── theme.json # Theme configuration
└── style.css # Theme metadata
Legacy Folder Names
For backward compatibility, WordPress also checks:
block-templates/(instead oftemplates/)block-template-parts/(instead ofparts/)
Template Resolution Flow
- Request comes in (e.g., viewing a single post)
- WordPress determines template type (
single) locate_block_template()is called- Builds template hierarchy (
single-post-{slug},single-post,single,singular,index) - Queries database for user-customized templates
- Falls back to theme files if no custom template
- Renders through
template-canvas.php
Template Canvas
Block templates are rendered through wp-includes/template-canvas.php, which:
- Sets up viewport meta tag
- Renders title tag
- Calls
get_the_block_template_html()to process blocks - Wraps output in
.wp-site-blockscontainer
Template Identification
Templates use a composite ID format: {theme}//{slug}
Examples:
twentytwentyfour//singlemy-theme//page-abouttwentytwentyfour//header(template part)
Global Variables
When a block template is active:
| Variable | Description |
|---|---|
$_wp_current_template_content |
Raw block content of current template |
$_wp_current_template_id |
Template ID (e.g., theme//slug) |
Theme Support
Block templates require the theme to declare support:
// Usually automatic for block themes (those with templates/index.html)
add_theme_support( 'block-templates' );
Check if supported:
if ( current_theme_supports( 'block-templates' ) ) {
// Block templates are active
}
Empty Template Handling
Since WordPress 6.8, empty templates display a warning to logged-in users via wp_render_empty_block_template_warning(), prompting them to edit the template in the Site Editor.
Related Files
wp-includes/block-template.php– Core template loading functionswp-includes/block-template-utils.php– Utility functions for templateswp-includes/class-wp-block-template.php– Template object classwp-includes/class-wp-block-templates-registry.php– Template registrationwp-includes/template-canvas.php– Template rendering wrapper