Most commercial WordPress themes still ship a 250 KB monolithic stylesheet, twenty PHP template files copied from 2016, and a visual builder plugin that wraps every paragraph in five nested <div> containers before the browser paints a single pixel. Modern wordpress custom block theme development throws out that entire stack: a minimal block theme needs only style.css, theme.json, and templates/index.html, letting WordPress core compile your design tokens into scoped CSS variables and render only the block styles actually used on the URL. Below is the complete engineering blueprint for building a production Full Site Editing (FSE) block theme from scratch on theme.json schema v3—with zero builder dependency and sub-100 ms Interaction to Next Paint (INP).
Table of Contents
- Classic PHP Themes vs Block Themes: The Runtime Delta
- How WordPress Resolves Block Templates and theme.json
- Step 1: Minimum Viable File Structure
- Step 2: Engineering theme.json Schema v3
- Step 3: Building HTML Block Templates and Template Parts
- Step 4: Auto-Registered PHP Block Patterns
- Step 5: Style Variations and Per-Block On-Demand CSS
- Troubleshooting Block Theme Edge Cases
- Related Content
Classic PHP Themes vs Block Themes: The Runtime Delta
A classic WordPress theme executes PHP templates directly (single.php calls get_header(), runs the loop, calls get_sidebar(), and closes with get_footer()). Every component shares one global stylesheet because the server does not know which shortcodes or widgets will render until the HTML stream is already halfway to the client.
A block theme changes the rendering order. WordPress locates an HTML block template (templates/single.html) before sending output, parses its block comment tree into memory, resolves the active theme.json hierarchy into --wp--preset--* and --wp--custom--* CSS custom properties, and enqueues only the stylesheets for blocks present on that page (should_load_separate_core_block_assets defaults to true for block themes).
| Architectural Dimension | Classic PHP Theme | Visual Page Builder Theme | Native FSE Block Theme (theme.json v3) |
|---|---|---|---|
| Minimum Required Files |
style.css + index.php
|
Parent theme + builder plugin + add-on pack |
style.css + templates/index.html + theme.json
|
| CSS Delivery Model | Monolithic style.css (80–300 KB) on every URL |
Monolithic theme CSS + per-page generated builder CSS | Inline global-styles-inline-css (~6–12 KB) + per-block CSS on demand |
| Typical Article DOM Nodes | 650 to 1,100 nodes | 1,800 to 3,600 nodes (deep wrapper nesting) | 380 to 650 nodes (1 wrapper per block) |
| Design Token Storage | Scattered across Customizer theme_mod rows and SASS files |
Serialized JSON/arrays in wp_postmeta per post |
Single theme.json contract + optional wp_global_styles user diff |
| Template Editability | Requires FTP or child theme PHP overrides | Proprietary drag-and-drop canvas with vendor lock-in | Native Site Editor (Appearance > Editor) exporting clean HTML |
| Frontend JS Runtime | Theme jQuery scripts (navigation.js, sliders) |
60–250 KB builder runtime + animation libraries | Zero baseline JS; Interactivity API modules load only where declared |
Verdict: if you control the theme layer, every kilobyte you move out of PHP callbacks and builder widgets into theme.json pays back on every single request.
How WordPress Resolves Block Templates and theme.json
When a request arrives for a single post or a custom post type, WordPress merges four configuration origins inside WP_Theme_JSON_Resolver and simultaneously resolves the block template hierarchy across disk and the wp_template custom post type.
graph TD
A[Incoming Request] --> B[WP_Theme_JSON_Resolver]
B --> C[Layer 1: Core Default theme.json]
C --> D[Layer 2: Active Theme theme.json v3]
D --> E[Layer 3: Child Theme or styles/*.json Variation]
E --> F[Layer 4: User Customizations in wp_global_styles CPT]
F --> G[Compiled CSS Variables in global-styles-inline-css]
A --> H[Block Template Locator]
H --> I{User Edit in wp_template CPT?}
I -->|Yes| J[Load DB Block Markup]
I -->|No| K[Load Theme templates/*.html File]
J --> L[Expand parts/*.html and patterns/*.php]
K --> L
L --> M[do_blocks Canvas Renderer]
G --> M
M --> N[Final HTML + Only Used Block Styles]
Two rules in this pipeline save hours of debugging:
-
Database edits shadow disk files. The moment an administrator edits
templates/single.htmlinside Appearance > Editor > Templates and clicks Save, WordPress writes a post ofpost_type = 'wp_template'intowp_posts. From that second forward, changes you make totemplates/single.htmlin Git will not show on the site until you click Reset on that template in the Site Editor (or delete thewp_templaterow via WP-CLI). -
theme.jsonlayers merge deep by key. User style edits stored in thewp_global_stylescustom post type sit at Layer 4. When you add a new color slug to your theme'stheme.jsonon disk, it merges cleanly with Layer 4; when you change an existing color value that a user already customized in the UI, Layer 4 wins until the user resets styles.
Step 1: Minimum Viable File Structure
Create a clean directory under wp-content/themes/kx-block-starter/. Every folder in a block theme has a reserved role in core discovery—do not invent custom directory names for templates or patterns unless you plan to filter theme_file_path.
wp-content/themes/kx-block-starter/
├── style.css /* Theme header metadata only (zero or minimal CSS) */
├── theme.json /* Schema v3 design tokens, layout rules, block styles */
├── functions.php /* Editor assets, block style variations, script setup */
├── templates/
│ ├── index.html /* Mandatory fallback template */
│ ├── front-page.html /* Homepage template */
│ ├── single.html /* Single post template */
│ ├── page.html /* Static page template */
│ ├── archive.html /* Category, tag, and date archives */
│ └── 404.html /* Not-found template */
├── parts/
│ ├── header.html /* Semantic <header> template part */
│ └── footer.html /* Semantic <footer> template part */
├── patterns/
│ ├── hero-metrics.php /* Auto-registered PHP block pattern */
│ └── post-card-grid.php /* Query loop pattern */
├── styles/
│ └──light-studio.json /* Optional whole-theme style variation */
└── assets/
├── fonts/
│ └── inter-var.woff2 /* Self-hosted variable WOFF2 font */
└── css/
└── blocks/
└── quote-glass.css /* On-demand CSS for core/quote only */
Your style.css file no longer needs 4,000 lines of reset and layout rules. Keep only the required WordPress theme header comment so core recognizes the theme and enforces your minimum WordPress and PHP versions:
/*
Theme Name: Kinetix Block Starter
Theme URI: https://kinetix.software
Author: Istiak Ahamed
Author URI: https://istiakahamed.com
Description: Lightweight theme.json v3 block theme with a CSS-variable design engine.
Version: 1.0.0
Requires at least: 6.6
Tested up to: 6.8
Requires PHP: 8.1
License: GPL-2.0-or-later
Text Domain: kx-block-starter
*/
Why Requires at least: 6.6? Because theme.json version 3 landed in WordPress 6.6. Declaring 6.6 prevents activation on older installs whose schema parser only understands version 2.
Step 2: Engineering theme.json Schema v3
theme.json is the single source of truth for both the block editor UI and the frontend CSS engine. Every preset you define under settings generates a CSS custom property (--wp--preset--color--<slug>, --wp--preset--font-size--<slug>, --wp--preset--spacing--<slug>), and every rule under styles consumes those properties without writing raw selectors by hand.
What Changed in theme.json Version 3 (WordPress 6.6+)
Upgrading "version": 2 to "version": 3 without adjusting your typography and spacing flags is the number-one cause of duplicated font and spacing presets in modern block themes.
| Property / Behavior | Schema Version 2 (WP 5.9–6.5) | Schema Version 3 (WP 6.6+) | Migration Action Required |
|---|---|---|---|
$schema URL |
https://schemas.wp.org/wp/6.5/theme.json |
https://schemas.wp.org/trunk/theme.json |
Point IDE validation to v3 / trunk schema |
settings.typography.defaultFontSizes |
Implicitly disabled when theme defined matching slugs (small, medium, large, x-large) |
Defaults to true; core font sizes stay visible alongside theme sizes unless turned off |
Explicitly set "defaultFontSizes": false
|
settings.spacing.defaultSpacingSizes |
Implicitly overridden by theme spacingSizes or spacingScale
|
Defaults to true; core spacing slugs (20–80) merge with theme sizes unless turned off |
Explicitly set "defaultSpacingSizes": false
|
settings.color.defaultPalette |
Defaults to true
|
Defaults to true (consistent with font/spacing flags) |
Set "defaultPalette": false and "defaultGradients": false
|
| Section Styling & Block Style Variations | Required PHP registration or full variation JSON | Supports scoped block style variation JSON files under styles/
|
Place partial variation files in styles/block-*.json
|
Production theme.json v3 Configuration
Save this file at wp-content/themes/kx-block-starter/theme.json. Notice how every spacing value, font scale, and surface color is defined once and referenced through var(--wp--preset--*) and var(--wp--custom--*):
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 3,
"settings": {
"appearanceTools": true,
"useRootPaddingAwareAlignments": true,
"layout": {
"contentSize": "760px",
"wideSize": "1200px"
},
"color": {
"defaultPalette": false,
"defaultGradients": false,
"defaultDuotone": false,
"custom": false,
"palette": [
{ "name": "Void Canvas", "slug": "canvas", "color": "#09090b" },
{ "name": "Raised Surface", "slug": "surface", "color": "#141418" },
{ "name": "Primary Text", "slug": "ink", "color": "#fafafa" },
{ "name": "Muted Text", "slug": "muted", "color": "#a1a1aa" },
{ "name": "Cobalt Accent", "slug": "accent", "color": "#38bdf8" },
{ "name": "Hairline Border", "slug": "border", "color": "#27272a" }
]
},
"typography": {
"defaultFontSizes": false,
"customFontSize": false,
"fluid": true,
"fontFamilies": [
{
"name": "Inter",
"slug": "sans",
"fontFamily": "'Inter', -apple-system, BlinkMacSystemFont, sans-serif",
"fontFace": [
{
"fontFamily": "Inter",
"fontWeight": "300 800",
"fontStyle": "normal",
"fontStretch": "normal",
"fontDisplay": "swap",
"src": [ "file:./assets/fonts/inter-var.woff2" ]
}
]
},
{
"name": "JetBrains Mono",
"slug": "mono",
"fontFamily": "'JetBrains Mono', ui-monospace, SFMono-Regular, monospace"
}
],
"fontSizes": [
{ "name": "XS", "slug": "xs", "size": "0.8125rem", "fluid": false },
{ "name": "Small", "slug": "sm", "size": "0.9375rem", "fluid": false },
{ "name": "Base", "slug": "base", "size": "1.0625rem", "fluid": false },
{
"name": "Large",
"slug": "lg",
"size": "1.375rem",
"fluid": { "min": "1.1875rem", "max": "1.375rem" }
},
{
"name": "XL",
"slug": "xl",
"size": "2rem",
"fluid": { "min": "1.5rem", "max": "2rem" }
},
{
"name": "Display",
"slug": "2xl",
"size": "3rem",
"fluid": { "min": "2.125rem", "max": "3rem" }
}
]
},
"spacing": {
"defaultSpacingSizes": false,
"units": [ "px", "rem", "%" ],
"spacingSizes": [
{ "name": "1 (8px)", "slug": "10", "size": "0.5rem" },
{ "name": "2 (16px)", "slug": "20", "size": "1rem" },
{ "name": "3 (24px)", "slug": "30", "size": "1.5rem" },
{ "name": "4 (40px)", "slug": "40", "size": "2.5rem" },
{ "name": "5 (64px)", "slug": "50", "size": "4rem" },
{ "name": "6 (96px)", "slug": "60", "size": "6rem" }
]
},
"custom": {
"radius": {
"sm": "8px",
"md": "14px",
"lg": "20px"
},
"lineHeight": {
"tight": "1.2",
"body": "1.75"
}
}
},
"styles": {
"color": {
"background": "var(--wp--preset--color--canvas)",
"text": "var(--wp--preset--color--ink)"
},
"typography": {
"fontFamily": "var(--wp--preset--font-family--sans)",
"fontSize": "var(--wp--preset--font-size--base)",
"lineHeight": "var(--wp--custom--line-height--body)"
},
"spacing": {
"blockGap": "1.25rem",
"padding": {
"top": "0px",
"right": "var(--wp--preset--spacing--30)",
"bottom": "0px",
"left": "var(--wp--preset--spacing--30)"
}
},
"elements": {
"heading": {
"typography": {
"fontWeight": "700",
"lineHeight": "var(--wp--custom--line-height--tight)",
"letterSpacing": "-0.02em"
}
},
"h1": { "typography": { "fontSize": "var(--wp--preset--font-size--2xl)" } },
"h2": { "typography": { "fontSize": "var(--wp--preset--font-size--xl)" } },
"h3": { "typography": { "fontSize": "var(--wp--preset--font-size--lg)" } },
"link": {
"color": { "text": "var(--wp--preset--color--accent)" },
":hover": { "color": { "text": "var(--wp--preset--color--ink)" } }
},
"button": {
"color": {
"background": "var(--wp--preset--color--ink)",
"text": "var(--wp--preset--color--canvas)"
},
"border": { "radius": "var(--wp--custom--radius--sm)" },
"typography": { "fontWeight": "600", "fontSize": "var(--wp--preset--font-size--sm)" }
}
},
"blocks": {
"core/code": {
"color": {
"background": "var(--wp--preset--color--surface)",
"text": "var(--wp--preset--color--ink)"
},
"border": {
"color": "var(--wp--preset--color--border)",
"style": "solid",
"width": "1px",
"radius": "var(--wp--custom--radius--md)"
},
"spacing": {
"padding": {
"top": "var(--wp--preset--spacing--20)",
"right": "var(--wp--preset--spacing--20)",
"bottom": "var(--wp--preset--spacing--20)",
"left": "var(--wp--preset--spacing--20)"
}
},
"typography": {
"fontFamily": "var(--wp--preset--font-family--mono)",
"fontSize": "var(--wp--preset--font-size--xs)"
}
}
}
},
"templateParts": [
{ "name": "header", "title": "Header", "area": "header" },
{ "name": "footer", "title": "Footer", "area": "footer" }
]
}
Deep Dive: How settings.custom compiles camelCase keys into CSS variables
Everything you nest inside settings.custom in theme.json is flattened by WordPress into --wp--custom--* CSS variables attached to body (or :root depending on scope). Two naming conversions happen automatically during compilation:
-
Nested objects join with double hyphens (
--). For example,settings.custom.radius.mdoutputs--wp--custom--radius--md: 14px;. -
CamelCase keys convert to kebab-case. For example,
settings.custom.lineHeight.tightoutputs--wp--custom--line-height--tight: 1.2;.
Why use settings.custom instead of declaring your own :root block in style.css? Because tokens declared in settings.custom can be overridden cleanly by style variations (styles/*.json) and child themes without specificity wars or extra stylesheets. Also note "useRootPaddingAwareAlignments": true: when enabled alongside styles.spacing.padding.left and right, full-width blocks (alignfull) automatically stretch edge-to-edge using negative margins while constrained content keeps safe horizontal viewport padding on mobile screens.
Step 3: Building HTML Block Templates and Template Parts
In a block theme, templates live in templates/*.html and reusable structural regions live in parts/*.html. Never wrap a template part call in an extra <!-- wp:group --> just to get a <header> or <footer> HTML tag—pass "tagName":"header" or "tagName":"footer" directly on the wp:template-part comment attributes. That single habit removes two redundant wrapper levels from every page.
Semantic Header Template Part (parts/header.html)
<!-- wp:group {"layout":{"type":"constrained","contentSize":"1200px"},"style":{"spacing":{"padding":{"top":"var:preset|spacing|20","bottom":"var:preset|spacing|20"}},"border":{"bottom":{"color":"var:preset|color|border","width":"1px"}}}} -->
<div class="wp-block-group" style="border-bottom-color:var(--wp--preset--color--border);border-bottom-width:1px;padding-top:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20)">
<!-- wp:group {"layout":{"type":"flex","flexWrap":"nowrap","justifyContent":"space-between"}} -->
<div class="wp-block-group">
<!-- wp:site-title {"level":0,"style":{"typography":{"fontWeight":"700"}}} /-->
<!-- wp:navigation {"overlayMenu":"mobile","layout":{"type":"flex","justifyContent":"right"}} /-->
</div>
<!-- /wp:group -->
</div>
<!-- /wp:group -->
Look closely at "level":0 on wp:site-title. By default, core/site-title renders an <h1> tag, which collides with your post title <h1> on single articles. Setting "level":0 renders a <p class="wp-block-site-title"> instead, keeping a strict single-<h1> document outline on every URL.
Single Post Template (templates/single.html)
<!-- wp:template-part {"slug":"header","tagName":"header","area":"header"} /-->
<!-- wp:group {"tagName":"main","layout":{"type":"constrained"},"style":{"spacing":{"margin":{"top":"var:preset|spacing|50","bottom":"var:preset|spacing|60"}}}} -->
<main class="wp-block-group" style="margin-top:var(--wp--preset--spacing--50);margin-bottom:var(--wp--preset--spacing--60)">
<!-- wp:group {"tagName":"article","layout":{"type":"constrained"}} -->
<article class="wp-block-group">
<!-- wp:post-terms {"term":"category","style":{"typography":{"fontSize":"var:preset|font-size|xs","textTransform":"uppercase","letterSpacing":"0.08em"}}} /-->
<!-- wp:post-title {"level":1} /-->
<!-- wp:group {"layout":{"type":"flex","flexWrap":"wrap"},"style":{"typography":{"fontSize":"var:preset|font-size|sm"},"color":{"text":"var:preset|color|muted"}}} -->
<div class="wp-block-group has-muted-color has-text-color" style="font-size:var(--wp--preset--font-size--sm)">
<!-- wp:post-date /-->
<!-- wp:post-author-name /-->
</div>
<!-- /wp:group -->
<!-- wp:post-featured-image {"aspectRatio":"16/9","style":{"border":{"radius":"14px"},"spacing":{"margin":{"top":"var:preset|spacing|30","bottom":"var:preset|spacing|40"}}}} /-->
<!-- wp:post-content {"layout":{"type":"constrained"}} /-->
</article>
<!-- /wp:group -->
</main>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","tagName":"footer","area":"footer"} /-->
Mandatory Fallback Template (templates/index.html)
WordPress refuses to classify your theme as a block theme unless templates/index.html exists. It renders archives and blog listings whenever a more specific template (archive.html, home.html) is absent:
<!-- wp:template-part {"slug":"header","tagName":"header","area":"header"} /-->
<!-- wp:group {"tagName":"main","layout":{"type":"constrained","contentSize":"1200px"},"style":{"spacing":{"margin":{"top":"var:preset|spacing|50","bottom":"var:preset|spacing|60"}}}} -->
<main class="wp-block-group" style="margin-top:var(--wp--preset--spacing--50);margin-bottom:var(--wp--preset--spacing--60)">
<!-- wp:query-title {"type":"archive"} /-->
<!-- wp:query {"queryId":1,"query":{"perPage":9,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","inherit":true}} -->
<div class="wp-block-query">
<!-- wp:post-template {"layout":{"type":"grid","columnCount":3}} -->
<!-- wp:group {"tagName":"article","style":{"spacing":{"padding":{"top":"var:preset|spacing|30","right":"var:preset|spacing|30","bottom":"var:preset|spacing|30","left":"var:preset|spacing|30"}},"border":{"color":"var:preset|color|border","width":"1px","radius":"14px"},"color":{"background":"var:preset|color|surface"}},"layout":{"type":"constrained"}} -->
<article class="wp-block-group has-border-color has-surface-background-color has-background" style="border-color:var(--wp--preset--color--border);border-width:1px;border-radius:14px;padding:var(--wp--preset--spacing--30)">
<!-- wp:post-date {"style":{"typography":{"fontSize":"var:preset|font-size|xs"},"color":{"text":"var:preset|color|muted"}}} /-->
<!-- wp:post-title {"level":2,"isLink":true,"style":{"typography":{"fontSize":"var:preset|font-size|lg"}}} /-->
<!-- wp:post-excerpt {"moreText":"","excerptLength":24} /-->
</article>
<!-- /wp:group -->
<!-- /wp:post-template -->
<!-- wp:query-pagination {"layout":{"type":"flex","justifyContent":"space-between"}} -->
<!-- wp:query-pagination-previous /-->
<!-- wp:query-pagination-next /-->
<!-- /wp:query-pagination -->
</div>
<!-- /wp:query -->
</main>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","tagName":"footer","area":"footer"} /-->
Notice "inherit":true on the wp:query block inside templates/index.html. If you accidentally set "inherit":false on an archive template, WordPress ignores the main URL query (/category/tutorials/ or /page/2/) and renders the exact same static list of posts on every archive page.
Building a WooCommerce store on top of this block theme structure? Our companion guide on how to edit a WooCommerce product page without a builder shows how templates/single-product.html interacts with WooCommerce's classic hook compatibility layer (SingleProductTemplateCompatibility). And if your store sells multi-attribute items, pair that template with the database lookup rules in how to add product variations in WooCommerce without wrecking your database.
Step 4: Auto-Registered PHP Block Patterns
Never hardcode marketing copy, image URLs, or translatable headings directly inside .html template files—HTML files cannot execute esc_html__() or get_theme_file_uri(). Put static text and reusable layouts inside patterns/*.php and reference them from your HTML templates using <!-- wp:pattern {"slug":"kx-block-starter/hero-metrics"} /-->.
WordPress automatically scans the patterns/ folder on init and registers any .php file that carries a valid docblock header:
<?php
/**
* Title: Hero Banner with Performance Metrics
* Slug: kx-block-starter/hero-metrics
* Categories: featured, banner
* Viewport Width: 1200
* Block Types: core/post-content
* Description: High-contrast hero section with zero custom CSS classes.
*/
defined( 'ABSPATH' ) || exit;
?>
<!-- wp:group {"align":"wide","style":{"spacing":{"padding":{"top":"var:preset|spacing|50","bottom":"var:preset|spacing|50"}}},"layout":{"type":"constrained","contentSize":"960px"}} -->
<div class="wp-block-group alignwide" style="padding-top:var(--wp--preset--spacing--50);padding-bottom:var(--wp--preset--spacing--50)">
<!-- wp:paragraph {"style":{"typography":{"fontSize":"var:preset|font-size|xs","textTransform":"uppercase","letterSpacing":"0.1em"},"color":{"text":"var:preset|color|accent"}}} -->
<p class="has-accent-color has-text-color" style="font-size:var(--wp--preset--font-size--xs);letter-spacing:0.1em;text-transform:uppercase"><?php echo esc_html__( 'Block-Native Architecture', 'kx-block-starter' ); ?></p>
<!-- /wp:paragraph -->
<!-- wp:heading {"level":1,"style":{"typography":{"fontSize":"var:preset|font-size|2xl"}}} -->
<h1 class="wp-block-heading" style="font-size:var(--wp--preset--font-size--2xl)"><?php echo esc_html__( 'Sub-Second WordPress Publishing Without Builder Overhead', 'kx-block-starter' ); ?></h1>
<!-- /wp:heading -->
<!-- wp:buttons {"style":{"spacing":{"margin":{"top":"var:preset|spacing|30"}}}} -->
<div class="wp-block-buttons" style="margin-top:var(--wp--preset--spacing--30)">
<!-- wp:button -->
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="<?php echo esc_url( home_url( '/docs' ) ); ?>"><?php echo esc_html__( 'Read the Architecture Docs', 'kx-block-starter' ); ?></a></div>
<!-- /wp:button -->
</div>
<!-- /wp:buttons -->
</div>
<!-- /wp:group -->
To keep the pattern inserter clean for editors, disable core remote patterns from the WordPress.org Pattern Directory inside functions.php using remove_theme_support( 'core-block-patterns' ); on after_setup_theme.
Step 5: Style Variations and Per-Block On-Demand CSS
One of the sharpest advantages of wordpress custom block theme development is shipping alternative color and typography themes without adding a single byte to the frontend CSS payload. Any JSON file placed inside styles/ (such as styles/light-studio.json) appears automatically under Appearance > Editor > Styles as a one-click theme switch:
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 3,
"title": "Light Studio",
"settings": {
"color": {
"palette": [
{ "name": "Void Canvas", "slug": "canvas", "color": "#f5f5f7" },
{ "name": "Raised Surface", "slug": "surface", "color": "#ffffff" },
{ "name": "Primary Text", "slug": "ink", "color": "#09090b" },
{ "name": "Muted Text", "slug": "muted", "color": "#52525b" },
{ "name": "Cobalt Accent", "slug": "accent", "color": "#0284c7" },
{ "name": "Hairline Border", "slug": "border", "color": "#e4e4e7" }
]
}
}
}
Because Light Studio reuses the exact same six color slugs (canvas, surface, ink, muted, accent, border) defined in your base theme.json, every template, pattern, and block border flips cleanly between dark and light palettes without a single duplicate CSS rule.
Loading Custom Block CSS Only When the Block Renders
When you need CSS that theme.json cannot express (such as backdrop-filter: blur(12px) glass surfaces or pseudo-elements), never dump it into a global stylesheet. Use wp_enqueue_block_style() inside functions.php so WordPress inlines that CSS file only on pages that actually render that specific block:
<?php
/**
* Kinetix Block Starter — functions.php
* Registers block style variations and per-block on-demand stylesheets.
*/
defined( 'ABSPATH' ) || exit;
add_action( 'after_setup_theme', function () {
// Remove remote WordPress.org patterns so only curated theme patterns appear.
remove_theme_support( 'core-block-patterns' );
} );
add_action( 'init', function () {
// 1. Register a custom "Glass Card" style pill in the editor for core/quote.
register_block_style(
'core/quote',
array(
'name' => 'kx-glass',
'label' => __( 'Glass Surface', 'kx-block-starter' ),
)
);
// 2. Attach a tiny stylesheet that ONLY loads on URLs containing a core/quote block.
wp_enqueue_block_style(
'core/quote',
array(
'handle' => 'kx-block-quote-glass',
'src' => get_theme_file_uri( 'assets/css/blocks/quote-glass.css' ),
'path' => get_theme_file_path( 'assets/css/blocks/quote-glass.css' ),
'ver' => wp_get_theme()->get( 'Version' ),
)
);
} );
Passing both 'src' and 'path' to wp_enqueue_block_style() is critical: when 'path' is provided, WordPress reads the file from disk and inlines it directly into <head> (up to styles_inline_size_limit, which defaults to 20,000 bytes), saving an external render-blocking HTTP request.
Advanced: Pure JSON Block Style Variations in WordPress 6.6+
If your custom block style (is-style-kx-surface-card) only adjusts properties that theme.json already supports (background, text color, border, padding, box-shadow), you no longer need register_block_style() or a .css file at all in WordPress 6.6+. Create a partial JSON file at styles/block-surface-card.json with a blockTypes array at the top level:
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 3,
"title": "Surface Card",
"slug": "surface-card",
"blockTypes": [ "core/group", "core/columns" ],
"styles": {
"color": {
"background": "var(--wp--preset--color--surface)",
"text": "var(--wp--preset--color--ink)"
},
"border": {
"color": "var(--wp--preset--color--border)",
"style": "solid",
"width": "1px",
"radius": "var(--wp--custom--radius--md)"
},
"spacing": {
"padding": {
"top": "var(--wp--preset--spacing--30)",
"right": "var(--wp--preset--spacing--30)",
"bottom": "var(--wp--preset--spacing--30)",
"left": "var(--wp--preset--spacing--30)"
}
}
}
}
WordPress automatically registers the Surface Card style button on Group and Columns blocks, and lets users customize that variation visually inside the Site Editor's Global Styles panel.
Kinetix (kinetix.software) applies this exact architecture in production: a dark-first WordPress theme engineered around a CSS-variable design engine, glass surface tokens, and block-editor templates with zero page-builder runtime. You can inspect how its typography presets, starter sites, and companion plugin (Kinetix Core) are structured in the Kinetix user guide and track template-level updates in the release changelog.
Once your block theme is rendering minimal DOM markup and scoped block CSS, pair it with server-side tuning—stripping core emoji scripts, cleaning up autoloaded rows in wp_options, and configuring Redis object caching—in our full walkthrough on WordPress speed optimization without a plugin.
Troubleshooting Block Theme Edge Cases
1. Changes to templates/single.html or theme.json on disk do not appear on the frontend
Two separate caches cause this:
-
Database template override (
wp_template/wp_template_part): If you ever clicked Save on that template inside Appearance > Editor, WordPress is serving the database row fromwp_postsinstead of your file on disk. Runwp post list --post_type=wp_template,wp_template_partvia WP-CLI to see which templates have database overrides, or open Appearance > Editor > Templates, click the three-dot menu next to the template, and click Reset. -
Global Styles transient & object cache: WordPress caches compiled
theme.jsonCSS in the object cache under theglobal_stylesgroup. While developing locally, setdefine( 'WP_DEVELOPMENT_MODE', 'theme' );inwp-config.php(introduced in WordPress 6.3). That constant bypasses thetheme.jsonand pattern caches automatically on every page refresh without disabling object caching for the rest of WordPress.
2. Custom fonts declared in theme.json return 404 or trigger duplicate downloads
Check the src path inside settings.typography.fontFamilies[].fontFace:
- It must begin with the prefix
file:./relative to your theme root (for example,"file:./assets/fonts/inter-var.woff2"). Omittingfile:./makes WordPress output a broken relative URL. - If you also preload that same WOFF2 file via the
wp_preload_resourcesfilter, make sure your preload array includes'crossorigin' => 'anonymous'. Browsers fetch@font-facefiles in anonymous CORS mode; a `tag withoutcrossorigin` creates a second network download for the exact same font file.
3. Classic plugin shortcodes or PHP hooks break inside a block template
If you are migrating a site that relies on custom post meta or legacy PHP action hooks:
-
For custom fields (WordPress 6.5+): Use the Block Bindings API instead of writing a custom shortcode. Bind a core Paragraph or Heading block directly to a registered meta key (
register_post_meta()with'show_in_rest' => true) via themetadata.bindingsattribute in block markup, as detailed in our guide to WordPress custom fields without a plugin, or build a structured backend form using WordPress custom meta box development without a plugin. -
For legacy PHP hooks: Never put raw
tags inside `templates/*.html`—HTML templates do not run through the PHP interpreter. Instead, place your `do_action( 'my_custom_hook' );` inside a PHP block pattern (`patterns/custom-hook-slot.php`) and include that pattern inside the HTML template with. - Evaluating stack trade-offs: Compare this block-native WordPress architecture against headless and custom SSR builds in our WordPress vs custom website speed and cost benchmark.
Related Content
-
WordPress Dark Mode Without Plugin: CSS & theme.json: layer semantic light/dark CSS tokens,
prefers-color-scheme, and a zero-flashwp_headtoggle onto yourtheme.jsonv3 palette. - How to Submit a Theme to WordPress.org: Review Guide: prepare your theme for the official WordPress.org directory with late escaping, GPL asset credits, and the Trac review checklist.
-
How to Edit a WooCommerce Product Page Without a Builder: customize
templates/single-product.htmland PHP summary hooks without adding page-builder DOM depth or hurting INP. -
WordPress Speed Optimization Without a Plugin: Code Guide: strip unused core front-end scripts, dequeue WooCommerce assets conditionally, clean up
wp_optionsautoload, and configure Redis object caching. - How to Add Product Variations in WooCommerce (Without Wrecking Your Database): structure global attributes, bulk-edit variations, and tune the 30-variant AJAX cutoff for fast catalog pages.
Originally published at https://kinetix.software/blog/wordpress-custom-block-theme-development.
Top comments (0)