WordPress 5.9 Full Site Editing: the structure of a block theme
WordPress 5.9 (January 2022) made Full Site Editing stable. The block editor now edits not only the post content but the whole site: header, footer, archives, single post templates, the 404 page. In a block theme, PHP templates (header.php, single.php) are replaced by HTML files with block markup in the templates and parts folders, and theme.json (version 2) holds the design settings. Templates are edited visually in the Site Editor (Appearance → Editor).
Problem: Build a minimal block theme for WordPress 5.9: what files are required and what goes into them?
Solution: A block theme needs only style.css with the theme header and templates/index.html. Add theme.json for the settings and template parts in parts for the header and footer.
The structure
my-block-theme/
├── style.css required: theme header
├── theme.json settings and styles (version 2)
├── functions.php optional
├── templates/
│ ├── index.html required: the fallback template
│ ├── single.html optional
│ └── 404.html optional
└── parts/
├── header.html
└── footer.html
WordPress treats a theme as a block theme when it has templates/index.html. The template hierarchy is the same as for classic themes, only the files are .html: single.html, page.html, archive.html, single-movie.html and so on.
style.css
/* Theme Name: My Block Theme Description: A minimal Full Site Editing block theme. Version: 1.0.0 Requires at least: 5.9 Requires PHP: 7.0 Text Domain: my-block-theme */
theme.json
{
"version": 2,
"settings": {
"color": {
"palette": [
{ "slug": "primary", "color": "#0073aa", "name": "Primary" },
{ "slug": "dark", "color": "#1e1e1e", "name": "Dark" }
]
},
"layout": { "contentSize": "720px", "wideSize": "1200px" }
},
"styles": {
"typography": { "fontFamily": "system-ui, sans-serif", "lineHeight": "1.6" }
},
"templateParts": [
{ "name": "header", "title": "Header", "area": "header" },
{ "name": "footer", "title": "Footer", "area": "footer" }
]
}
The palette appears in the color controls of the editor, layout sets the width of the content and of wide blocks, and templateParts tells the Site Editor which part is the header and which is the footer.
templates/index.html
Plain block markup, the same as in post content:
<!-- wp:template-part {"slug":"header","tagName":"header"} /-->
<!-- wp:group {"tagName":"main","layout":{"inherit":true}} -->
<main class="wp-block-group">
<!-- wp:query {"queryId":0,"query":{"perPage":10,"postType":"post","inherit":true}} -->
<div class="wp-block-query">
<!-- wp:post-template -->
<!-- wp:post-title {"isLink":true} /-->
<!-- wp:post-excerpt /-->
<!-- /wp:post-template -->
<!-- wp:query-pagination -->
<!-- wp:query-pagination-previous /-->
<!-- wp:query-pagination-numbers /-->
<!-- wp:query-pagination-next /-->
<!-- /wp:query-pagination -->
</div>
<!-- /wp:query -->
</main>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","tagName":"footer"} /-->
"inherit":true in the Query Loop makes it use the main query of the page, so the same template works for the blog, archives and search.
parts/header.html is block markup too, for example <!-- wp:site-title /--> and <!-- wp:navigation /--> in a group.
functions.php
Most of what add_theme_support() did in classic themes (palettes, font sizes, widths) is now in theme.json. functions.php is only needed for your own styles and hooks:
<?php
add_action( 'wp_enqueue_scripts', function () {
wp_enqueue_style( 'my-block-theme', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
} );
NOTE: When a user edits a template in the Site Editor, the change is saved in the database and overrides the theme file. Edits in templates/*.html are then not visible until the user resets the template (“Clear customizations”). Converting a classic theme is not an upgrade but a rebuild: it is usually easier to start a new block theme and move the design into theme.json.