theme.json Custom Properties: One Declaration, Two Surfaces, and the Naming Rules That Break Them

The failure report is almost always the same shape: a theme defines a value under settings.custom, writes var(--my-thing) in a stylesheet, and gets nothing in the editor and nothing on the frontend. The author assumes the property never loaded. Usually it loaded fine. The author guessed the name.

This is worth treating as a naming failure before a loading failure, because the naming rules are mechanical and the loading path is not something you control. WordPress generates the custom property name from your JSON keys. If your var() call does not match the generated string exactly, the declaration exists and your CSS ignores it.

Symptom: the property resolves in one place and not the other

Two variants show up in practice. In the first, the property is undefined everywhere, which points at the name. In the second, it resolves on the frontend but not inside the editor canvas, which points at scope — a block-level declaration that the editor’s wrapper markup does not match the way the frontend does.

Before changing any PHP, open DevTools on the frontend, select the body element, and read the computed custom properties. Then open the editor, select the block canvas, and do the same. If the property is absent from both, the name is wrong. If it is present on the frontend and absent in the editor, read the selector it landed on and compare it to the editor’s DOM.

Trace: what settings.custom actually produces

The theme.json documentation is explicit that values under the custom field are transformed into CSS custom properties following the schema --wp--custom--<variable-name>. A top-level example with nested line-height values produces this output on body:

{
  "version": 3,
  "settings": {
    "custom": {
      "line-height": {
        "body": 1.7,
        "heading": 1.3
      }
    }
  }
}
body {
  --wp--custom--line-height--body: 1.7;
  --wp--custom--line-height--heading: 1.3;
}

Two rules are doing the work here. Camel-cased keys are hyphenated, so textShadow becomes text-shadow. Nested levels are joined with a double hyphen, so formInput with a borderColor child becomes --wp--custom--form-input--border-color. The theme.json reference states both rules directly: camelCased keys are transformed to kebab-case, and keys at different depth levels are separated by --.

The practical consequence is that the property name is a function of your JSON structure, not of the label you had in mind. A key named brandBlue at the top level yields --wp--custom--brand-blue. A key named brand containing blue yields --wp--custom--brand--blue. Those are different strings, and only one of them exists.

Root cause: the generated stylesheet is the shared artifact

The reason to define these values in theme.json rather than a hand-written :root block is not tidiness. It is that WordPress outputs the generated custom properties in the editor and on the frontend from the same theme.json data. The developer news article on custom settings puts it plainly: custom settings are not tied to interface controls; what you are doing is configuring CSS custom properties that WordPress outputs in the editor and on the front end. The same article notes that a settings.custom.textShadow value is generated automatically and loaded on both surfaces.

That shared origin is the whole argument. A hand-written :root block in a frontend stylesheet does not reach the editor canvas unless you also enqueue it there, and the two copies drift the moment someone edits one. The theme.json path removes that class of drift by construction. It does not remove naming drift, which is why the failure mode above persists.

Under the hood, the WP_Theme_JSON class handles the conversion. Its reference page marks the class as private, intended for core rather than extenders, and points developers at get_global_settings, get_global_styles, and get_global_stylesheet instead. Treat the class as a read-only curiosity during debugging. Reaching into it from a theme or plugin is a maintenance liability on an install you have to keep running.

Fix: write the name the generator writes

Start from the JSON, derive the name, and only then write the var() call. A grouped example makes the derivation obvious:

{
  "$schema": "https://schemas.wp.org/trunk/theme.json",
  "version": 3,
  "settings": {
    "custom": {
      "formInput": {
        "color": "#000000",
        "background": "#f1f5f9",
        "borderColor": "#e2e8f0"
      }
    }
  }
}

That produces three declarations on body:

body {
  --wp--custom--form-input--color: #000000;
  --wp--custom--form-input--background: #f1f5f9;
  --wp--custom--form-input--border-color: #e2e8f0;
}

Consume them with a fallback so a future rename fails visibly rather than silently:

input:where(:not([type=checkbox]):not([type=radio])),
select,
textarea {
  color: var(--wp--custom--form-input--color, inherit);
  background: var(--wp--custom--form-input--background, transparent);
  border: 1px solid var(--wp--custom--form-input--border-color, currentColor);
}

The fallback is not decoration. It converts an undefined property into a visible wrong color instead of an invisible no-op, which shortens the next debugging session.

Per-block custom properties are a scoping tool

Custom values can also be declared per block. A heading-level override looks like this:

{
  "version": 3,
  "settings": {
    "custom": {
      "textShadow": "2px 2px 2px rgba(0, 0, 0, 0.3)"
    },
    "blocks": {
      "core/heading": {
        "custom": {
          "textShadow": "2px 2px 2px rgba(0, 0, 0, 0.7)"
        }
      }
    }
  }
}

The generated output scopes the block value to the block selector rather than body:

body {
  --wp--custom--text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.3);
}
.wp-block-heading {
  --wp--custom--text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.7);
}

This is where the second failure variant comes from. A block-scoped property is only readable by CSS that resolves inside that block’s selector. If you declare the value under settings.blocks['core/heading'].custom and then reference it from a rule targeting an element outside the heading, the variable is undefined at that point in the cascade. The fix is to move the declaration to top-level settings.custom if the value needs to be readable from arbitrary CSS, and keep the block-level declaration only for values that genuinely belong to the block’s own scope.

Editor wrappers complicate this further. The editor canvas wraps blocks in additional markup, so a selector that matches on the frontend may not match the same way inside the editor. If a property resolves on the frontend and not in the editor, inspect the editor DOM for the block and confirm the selector your declaration landed on is actually present there. The generated stylesheet is shared; the DOM it applies to is not identical.

Overrides inherit, which is useful and easy to misread

The theme.json system is hierarchical. A child theme or a style variation can override individual nested keys while the rest come from the parent. The developer news article demonstrates this with a child theme that sets only formInput.background and formInput.borderColor; the parent’s formInput.color still appears in the generated output.

That behavior is the reason to nest related values under a shared parent key rather than scattering them at the top level. A child theme can then override one leaf without redeclaring the group. It also means a missing property in the generated output may be a merge problem rather than a naming problem: check whether the parent declaration survived the merge before assuming the key was rejected.

For programmatic changes, the documented path is the server-side filters. WordPress 6.1 introduced filters for each theme.json data layer, including wp_theme_json_data_theme. Each receives a WP_Theme_JSON_Data instance, and the callback returns $theme_json->update_with( $new_data ) with a valid theme.json-like structure. That is the supported extension point; the WP_Theme_JSON class itself is not.

Verification: read the generated declaration before touching enqueue logic

The pre-flight check is short. Grep the generated stylesheet for the exact string you intend to reference, confirm the selector it lands on, and only then write the var() call.

On a self-maintained install, the fastest route is WP-CLI against the global stylesheet function:

wp eval 'echo wp_get_global_stylesheet();' | grep -n -- '--wp--custom--'

If the string you expected is absent, the problem is upstream of CSS: the key is misspelled, the nesting depth is wrong, or the declaration was filtered out. If the string is present, read the selector on the line above it. A declaration on body is readable almost anywhere; a declaration on .wp-block-heading is not.

Then confirm in both surfaces. On the frontend, select body in DevTools and read the computed custom properties. In the editor, select the block canvas and do the same. If the property is present in the generated stylesheet but absent from computed styles in one surface, the selector did not match that surface’s DOM — go back to the scope question, not the naming question.

One caution on the debugging command: wp_get_global_stylesheet() is the documented alternative to reaching into WP_Theme_JSON, but its caching behavior is not covered by the sources here. If the output looks stale after a theme.json edit, clear caches before concluding the declaration is missing.

Failure-mode checklist

  • Wrong nesting depth. brandBlue and brand.blue produce different property names. Derive the name from the JSON, not from intent.
  • Preset name assumed for a custom value. Presets generate --wp--preset--*; custom values generate --wp--custom--*. A palette entry does not become a custom property, and a custom value does not become a preset.
  • UI control expected. Custom settings are not tied to interface controls. If you need a control, that is a different part of the schema.
  • Block scope mistaken for global scope. A block-level declaration is only readable inside that block’s selector. Move it to top-level settings.custom if arbitrary CSS needs it.
  • Property referenced before confirming it exists. Grep the generated stylesheet first. The var() call is the last step, not the first.

Questions that come up

Does settings.custom reach the editor, or only the frontend?

Both. The developer news article states that WordPress generates the custom property and loads it on the front-end and in the editor. The generated stylesheet is the shared artifact; the difference between surfaces is the DOM it applies to, not the declarations themselves.

Why does my property work on the frontend but not in the editor?

Check the selector the declaration landed on. A block-scoped property applies only where that block selector matches. The editor wraps blocks in additional markup, so a selector that matches on the frontend may not match the same way inside the editor canvas. Inspect the editor DOM for the block before changing the JSON.

Can I reference a custom property from block markup attributes?

The sources here do not document a supported syntax for referencing settings.custom values from block markup attributes. A comment thread on the developer news article shows a user attempting a var:preset|custom|... form and reporting it did not work, which is not evidence of a supported mechanism. Keep custom properties in CSS and use them from CSS rules.

Should I call WP_Theme_JSON directly to inspect the data?

No. The class reference marks it private and points extenders at get_global_settings, get_global_styles, and get_global_stylesheet. For programmatic changes, use the data-layer filters such as wp_theme_json_data_theme with update_with().

Why does a child theme override only some of my values?

Because the system is hierarchical. Properties are inherited from the parent level, and a child theme or style variation can override individual nested keys while the rest come from the parent. That is expected behavior, not a merge bug.

Sources: WordPress Developer Resources, Global Settings & Styles (theme.json); Theme.json Version 3 Reference; WP_Theme_JSON class reference; Global Styles Filters; WordPress Developer News, Adding and using custom settings in theme.json.