Anatomy of WordPress Block Themes: Directory Structure and Files

Thinking about creating your first WordPress block theme but not sure where to begin? In this article, we’ll take a deep dive into the file structure of a block theme. We’ll explore which directories and files can be included, which ones are mandatory, and what purpose each serves in the modern Theme API.

To get started, I recommend downloading the Twenty Twenty-Four theme. It’s the current gold standard for block themes, and you can study its files to understand how to build and customize your own.

Important Note: This article assumes you are already an experienced WordPress developer who is transitionining to block-based development. While I won’t go into detail on how to code every specific block, this guide will provide the high-level architectural map you need to navigate block theme projects.

Block Theme Structure

A basic block theme consists of just a folder containing a style.css file and a templates/index.html file. However, a full-featured theme usually looks more like the structure shown in the screenshot below.

Typical WordPress Block Theme Directory Structure

The tables below list all the required and optional folders and files that make up a WordPress block theme.

Required Folders

Every block theme must include the following directory:

Folder NameDescription
templatesContains the main HTML template files. This folder must contain at least an index.html file.

Optional Folders

Technically, you can add any folder to a block theme for organization. However, WordPress recognizes these specific folders for core functionality:

Folder NameDescription
partsContains global template parts (headers, footers, sidebars).
patternsStores custom block patterns (reusable sections).
stylesHolds custom style variations (global style skins).

Required Files

These two files form the absolute minimum requirements for a WordPress block theme:

File NameDescription
style.cssContains theme “header” metadata (name, author, version). It also defines the main styles for the theme.
templates/index.htmlThe fallback template file used to display any page or post if no more specific template exists.

Files Required for WordPress.org

If you plan to distribute your theme via the official WordPress repository, you must include these additional files:

File NameDescription
readme.txtProvides theme information, installation instructions, license details, and changelogs.
screenshot.pngThe thumbnail image displayed in the WordPress Appearance > Themes dashboard. (Recommended even for private themes).

Optional Files

While optional, these files are central to modern block theme development:

File NameDescription
theme.jsonThe most important file in block themes. It defines global settings, styles, and block configurations for both the editor and the frontend.
functions.phpUsed to add custom PHP functionality, register hooks, and enqueue additional assets.
rtl.cssAutomated loading for Right-to-Left languages. (Often unnecessary with modern ‘logical’ CSS properties).
templates/*.htmlAdditional templates for specific layouts (home, page, single, archive, etc.).
parts/*.htmlReusable template components like headers and footers.
patterns/*.phpPHP files defining curated, reusable collections of blocks.
styles/*.jsonAlternate global style variations that users can select in the Site Editor.

Core Template File List

WordPress automatically selects templates based on the page being visited. The template hierarchy for block themes is identical to classic themes, following the standard logic familiar to WordPress developers.

File NameDescription
home.htmlDisplays the posts page (fallback for front-page).
single.htmlDisplays a single post.
page.htmlDisplays a single static page.
archive.htmlDisplays lists of posts (categories, tags, dates).
search.htmlDisplays search results.
404.htmlDisplays the error page when content isn’t found.

Conclusion

As you can see, the foundation of a block theme is remarkably simple, requires very few files to function, and offers a lot of room for customization through optional folders and JSON configurations. If you are ever stuck, just refer to core themes like Twenty Twenty-Four to see how they handle specific layouts.

If you have any questions about block theme architecture, feel free to leave a comment below!

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *