italystrap / theme-json-generator
WordPress theme.json generator from a PHP array
Package info
github.com/ItalyStrap/theme-json-generator
pkg:composer/italystrap/theme-json-generator
Requires
- php: >=8.2
- ext-json: *
- brick/varexporter: ^0.3.8
- composer/class-map-generator: ^1.6
- italystrap/config: ^2.4
- italystrap/empress: dev-modularized as 2.0.x-dev
- italystrap/finder: dev-master
- italystrap/pipeline: dev-main
- justinrainbow/json-schema: ^5.2
- mexitek/phpcolors: ^1.0
- overclokk/auryn: dev-master
- sabberworm/php-css-parser: ^8.5
- scssphp/scssphp: ^1.12.1
- spatie/color: ~1.5.0
- symfony/console: ^v5.4
- symfony/event-dispatcher: ^5.4
- symfony/process: ^v5.4
- webimpress/safe-writer: ^2.2
- webmozart/assert: ^1.11
Requires (Dev)
- codeception/module-asserts: ^3.0
- codeception/module-cli: ^2.0
- codeception/module-db: ^3.0
- codeception/module-filesystem: ^3.0
- codeception/module-phpbrowser: ^3.0
- codeception/util-universalframework: ^1.0
- dealerdirect/phpcodesniffer-composer-installer: ^1.0
- dg/bypass-finals: ^1.9
- infection/codeception-adapter: ^0.4.1
- infection/infection: ^0.26.6
- italystrap/debug: dev-master
- jangregor/phpstan-prophecy: ^2.3
- lucatume/wp-browser: ^4.5
- phenx/php-font-lib: ^0.5.6
- phpbench/phpbench: ^1.2
- phpcompatibility/php-compatibility: *
- phpmetrics/phpmetrics: ^2.8
- phpspec/prophecy-phpunit: ^2.0
- phpstan/phpstan: ^2.3.1
- rector/rector: ^2.4
- rector/swiss-knife: ^2.3
- slevomat/coding-standard: ^8.18
- squizlabs/php_codesniffer: *
- symplify/easy-coding-standard: ^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-18 14:46:22 UTC
README
Write WordPress theme.json configuration in PHP. Define settings, presets, and
styles through a fluent API, share configuration between variations, and generate
JSON during development or CI.
The package is experimental. These docs describe the current repository API; choose an installed version containing the features you need and review changes before upgrading.
Install
Requires PHP 8.2 or newer, the JSON extension, and Composer. From your theme root:
composer require --dev italystrap/theme-json-generator
The current package requires some development-branch dependencies. See installation for dependency stability, version selection, and global installation.
Generate your first configuration
Create theme.json.php in a theme containing style.css with a Theme Name: header:
<?php use ItalyStrap\ThemeJsonGenerator\ThemeJson; return static function (ThemeJson $themeJson): void { $themeJson->schema('https://schemas.wp.org/wp/6.6/theme.json'); $themeJson->version(3); $themeJson->title('Example Theme'); $themeJson->settings()->color()->addColor('primary', 'Primary', '#2457ab'); $themeJson->settings()->typography()->addFontSize('body', 'Body', '1rem'); $themeJson->styles()->color()->text('color.primary'); $themeJson->styles()->typography()->fontSize('fontSize.body'); };
Choose a schema and format version for your target WordPress release. Then run:
vendor/bin/theme-json dump
The command writes theme.json beside the entrypoint, resolving preset keys to
CSS variables. Edit PHP and regenerate; direct changes to generated JSON are
overwritten. To import an existing theme.json into a PHP entrypoint, run init.
For a complete walkthrough, follow the quick start.
What you can build
- Configure editor controls, layout, typography, and reusable presets.
- Apply global styles or target blocks, elements, states, and block style variations.
- Organize configuration classes into ordered pipelines.
- Generate variation JSON from
styles/*.json.phpentrypoints. - Add custom CSS or compile embedded SCSS into JSON.
- Export SCSS references for use in a separate Sass build.
- Start a customizable GitHub Actions generation workflow.
Generate JSON and assets before deployment. WordPress consumes the output; this generator does not need to run during production requests.
Documentation
Start at the documentation homepage, or open a topic directly:
| Task | Guide |
|---|---|
| Understand inputs, outputs, and generation | Workflow |
| Configure settings and reusable values | Settings · Presets |
| Style a theme or block | Styles and scopes · Custom CSS |
| Split configuration into classes | Configurators · Autoloading |
| Add alternative theme styles | Style variation files |
| Work with generated references or palettes | SCSS export · Colors |
| Automate a build | Build integration · GitHub Actions |
| Look up a command or method | CLI · API |
| Upgrade or solve a problem | Migration · Troubleshooting |
Prefer typed configuration APIs. For unsupported paths, use the root
ThemeJson::set(), get(), and appendTo() methods with explicit array paths;
string paths use Config dot notation. Root metadata methods such as schema(),
version(), title(), and slug() are covered in the entrypoint guide.
slug() is primarily for style variation metadata.
Contributing
See Contributing for development checks, source architecture,
and documentation maintenance. For schema/API planning, make report/api-inventory
generates Markdown and CSV reports in report/. See the inventory instructions
to map schema paths to typed methods.
Resources
License
Copyright (c) 2021 Enea Overclokk, ItalyStrap. Licensed under the MIT license.