The CantoThemes journal

,

How to Create a Block Theme in WordPress: Developer Guide

Create a WordPress block theme with a practical guide to required files, theme.json, templates, template parts, testing, and export.

Developer arranging website blocks beside a code panel, with menu, image, video, and typography elements

To create a block theme in WordPress, start with style.css and templates/index.html, then add theme.json for global settings and styles. You can edit templates in code or design them visually in the Site Editor.

This WordPress block theme tutorial builds a small starter theme with reusable headers and footers. You will learn the file structure, add a Query Loop, configure colors and spacing, and export your work. It assumes basic HTML and JSON knowledge; custom React blocks are not required.

How Block Themes Differ From Classic Themes

Classic themes use PHP templates, while block themes use HTML files containing block markup and support visual template editing in the Site Editor. Both can use PHP for theme features, and classic themes can also adopt theme.json. Performance depends on the implementation, assets, and plugins.

Before You Start

Work in a local or staging installation with a backup. Use a code editor, a supported WordPress version, and sample posts for testing. Our local WordPress development guide covers environment setup.

Step 1: The Minimum Required Files to Build an FSE Theme

Create my-block-theme/ inside the wp-content/themes/ directory of a local WordPress installation. WordPress requires these two files to recognize a block theme; index.php is not required. See the official block theme structure reference.

my-block-theme/
├── style.css
└── templates/
    └── index.html

1. style.css (The Theme Declaration)

Just like classic themes, you need a style.css file to declare the theme metadata. WordPress uses this file to identify your theme in the dashboard.

/*
Theme Name: My Custom Block Theme
Author: Your Name
Description: A starter block theme for the Site Editor.
Version: 1.0.0
*/

Use theme.json for supported global and block styles. Custom CSS is still useful when those controls do not cover a design. If you add CSS to style.css, enqueue it appropriately rather than assuming WordPress loads it automatically.

2. templates/index.html (The Core Template)

This fallback template uses block markup to show a list of posts. Copy the example into templates/index.html. Later, add dedicated templates such as single.html and page.html with Post Content blocks for complete individual posts and pages.

<!-- wp:site-title /-->
<!-- wp:query {"query":{"perPage":10,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true}} -->
<div class="wp-block-query">
    <!-- wp:post-template -->
        <!-- wp:post-title {"isLink":true} /-->
        <!-- wp:post-excerpt /-->
    <!-- /wp:post-template -->
</div>
<!-- /wp:query -->

Activate the starter under Appearance > Themes on your local site. Check that the posts appear, then continue with global styles. This is a learning scaffold, not a complete theme ready for production.

Step 2: Configure Styles With theme.json

Create theme.json in the theme root. It defines editor settings and default styles for colors, typography, spacing, and layout widths. The example uses version 2 of the format; choose a schema version compatible with your project’s minimum WordPress version.

The spacing presets below use settings.spacing.spacingSizes. The separate units setting accepts unit names such as px and rem, not preset objects. See the WordPress spacing settings reference.

{
  "version": 2,
  "settings": {
    "layout": {
      "contentSize": "800px",
      "wideSize": "1200px"
    },
    "color": {
      "palette": [
        {
          "slug": "primary",
          "color": "#005bb5",
          "name": "Primary Blue"
        },
        {
          "slug": "background",
          "color": "#f9f9f9",
          "name": "Background Light"
        }
      ]
    },
    "typography": {
      "fontFamilies": [
        {
          "fontFamily": "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif",
          "slug": "system-font",
          "name": "System Font"
        }
      ]
    },
    "spacing": {
      "units": [
        "px",
        "rem",
        "%"
      ],
      "spacingSizes": [
        {
          "name": "Small",
          "size": "1rem",
          "slug": "sm"
        },
        {
          "name": "Medium",
          "size": "2rem",
          "slug": "md"
        }
      ]
    }
  },
  "styles": {
    "color": {
      "background": "var(--wp--preset--color--background)",
      "text": "#333333"
    },
    "typography": {
      "fontFamily": "var(--wp--preset--font-family--system-font)",
      "lineHeight": "1.6"
    },
    "blocks": {
      "core/button": {
        "color": {
          "background": "var(--wp--preset--color--primary)",
          "text": "#ffffff"
        },
        "border": {
          "radius": "4px"
        }
      }
    }
  }
}

What does this do?

  1. Settings: Defines the available options in the block editor. It creates a custom color palette, limits the content width to 800px (and wide alignment to 1200px), and sets up spacing presets. WordPress automatically generates CSS variables for these (e.g., --wp--preset--color--primary).
  2. Styles: Applies those settings globally. It sets the body background color, default text color, and even targets specific blocks. The example gives core/button blocks a primary background color and 4px border radius as defaults; user styles can override them.

Validate this file against the schema for your minimum supported WordPress version. For distribution, add accurate compatibility and licensing metadata to style.css based on the versions you actually test.

Step 3: Building Template Parts (Headers and Footers)

Use template parts to share a header and footer across templates. Each template references the part by its file slug, so you can update the shared layout in one place.

Create a new folder named parts/.

Create parts/header.html:

<!-- wp:group {"layout":{"type":"flex","flexWrap":"nowrap","justifyContent":"space-between"},"style":{"spacing":{"padding":{"top":"var:preset|spacing|md","bottom":"var:preset|spacing|md"}}}} -->
<div class="wp-block-group" style="padding-top:var(--wp--preset--spacing--md);padding-bottom:var(--wp--preset--spacing--md)">
    <!-- wp:site-title {"level":0} /-->
    <!-- wp:navigation {"layout":{"type":"flex","setCascadingProperties":true,"justifyContent":"right"}} /-->
</div>
<!-- /wp:group -->

Create parts/footer.html:

<!-- wp:group {"layout":{"type":"constrained"},"style":{"spacing":{"padding":{"top":"var:preset|spacing|md","bottom":"var:preset|spacing|md"}}}} -->
<div class="wp-block-group" style="padding-top:var(--wp--preset--spacing--md);padding-bottom:var(--wp--preset--spacing--md)">
    <!-- wp:paragraph {"align":"center"} -->
    <p class="has-text-align-center">My Block Theme · Built with WordPress.</p>
    <!-- /wp:paragraph -->
</div>
<!-- /wp:group -->

Replace templates/index.html with this complete example. It wraps the inherited query in a main landmark and adds pagination and an empty state:

<!-- wp:template-part {"slug":"header","tagName":"header"} /-->

<!-- wp:group {"tagName":"main","layout":{"type":"constrained"}} -->
<main class="wp-block-group">
<!-- wp:query {"query":{"inherit":true}} -->
<div class="wp-block-query">
<!-- wp:post-template -->
<!-- wp:post-title {"isLink":true} /-->
<!-- wp:post-excerpt /-->
<!-- /wp:post-template -->
<!-- wp:query-pagination {"layout":{"type":"flex","justifyContent":"space-between"}} -->
<!-- wp:query-pagination-previous /-->
<!-- wp:query-pagination-numbers /-->
<!-- wp:query-pagination-next /-->
<!-- /wp:query-pagination -->
<!-- wp:query-no-results -->
<!-- wp:paragraph -->
<p>No posts found.</p>
<!-- /wp:paragraph -->
<!-- /wp:query-no-results -->
</div>
<!-- /wp:query -->
</main>
<!-- /wp:group -->

<!-- wp:template-part {"slug":"footer","tagName":"footer"} /-->

Step 4: Design and Export With Create Block Theme

You can combine code editing with the Site Editor. The Create Block Theme plugin helps create a blank theme or export templates and styles designed in WordPress.

On your local development site, follow this workflow:

  1. Install and activate Create Block Theme on the development site. Check its WordPress version requirements before installing.
  2. Activate the starter created above, or use the plugin’s Create Blank Theme action.
  3. Navigate to Appearance > Editor. You are now in the Site Editor.
  4. Design: Set global styles and arrange blocks in your templates, header, and footer.
  5. Open the plugin menu: In the Site Editor, open the Create Block Theme menu at the top.
  6. Select Export Zip to download the theme. Saving changes to the active theme is a separate action that modifies its files.

Open the exported ZIP and check its templates, styles, and assets. Install it on a fresh test site to confirm the design works without the original database customizations. Exporting is a packaging step; it does not replace testing.

Troubleshooting Common Full Site Editing (FSE) Issues

If the result differs from your files, check syntax, layout settings, and saved editor customizations before making larger changes.

1. The White Screen of Death / Site Editor Won’t Load

A blank Site Editor can have several causes, including invalid JSON, PHP errors, JavaScript errors, or plugin conflicts. Validate theme.json against the schema for your supported WordPress version, check the browser console and development error logs, and isolate conflicts on a local or staging site. A valid JSON file can still contain unsupported settings.

2. Blocks Are Not Aligning (Wide or Full Width)

Alignment options depend on the block’s capabilities, its parent layout, and theme settings. Check settings.layout.contentSize and wideSize, then inspect the parent Group’s layout and content-width controls. Full-width blocks may still be constrained by an ancestor container or custom CSS.

3. Changes in Code Aren’t Showing on the Frontend

Site Editor template customizations are stored in the database and can take priority over theme files. Export or back up those customizations first. Then use the template’s reset or clear-customizations action in Appearance > Editor > Templates to return to the theme file. Check caches too if the result is still stale.

How to Export and Package a Block Theme for the WordPress Repository

Before submitting a theme to WordPress.org, review the current Theme Directory requirements. The following is a preparation checklist, not an exhaustive review:

  1. Ensure Licensing: Your theme must be 100% GPL-compatible. This includes all fonts, images, and scripts bundled with it.
  2. Run Theme Check: Review and resolve its findings. Automated checks help identify issues but do not guarantee security or acceptance.
  3. Screenshot: Add a representative screenshot in the theme root. Follow the required 4:3 ratio and maximum dimensions of 1200 × 900 pixels.
  4. Pattern Inclusion: Ensure all placeholder images used in your templates and block patterns are bundled locally inside an assets/ folder in your theme, rather than hotlinked to external URLs.
  5. Zip and submit: Package the theme folder, test a fresh installation from the ZIP, and submit through the WordPress.org theme upload process.

Next Steps: Complete and Test Your Block Theme

You now have a starter block theme with a post-list template, global styles, and reusable template parts. Add dedicated templates for single posts, pages, archives, search, and 404 states as the project requires.

Before release, test with sample content on a fresh installation. Check navigation, pagination, long titles, empty results, keyboard access, mobile layouts, and plugin compatibility. Confirm your exported files reproduce the design without saved Site Editor overrides.

Written by

Previous story
Next story

Leave a Reply

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