A modular theme.json compiler for WordPress themes.
⚠️ WarningThe
compile
andwatch
commands will overwrite yourtheme.json
file in the specified theme directory.A backup is created automatically, but you may want to manually make one as well since this tool has not been thoroughly tested yet.
- Split
theme.json
into modular files for easier management - Compile modular files back into a single
theme.json
- Supports granular splitting for
settings
,styles
, and more - CLI commands for
compile
,split
, andwatch
npm install @builtnorth/wp-theme-json-compiler
- split: Splits a current
theme.json
file into modular JavaScript files in thetheme-config
directory. This makes it easier to manage and edit theme settings in a structured way. - compile: Compiles all modular files from the
theme-config
directory back into a singletheme.json
file. Automatically creates a backup of the existingtheme.json
before overwriting. - watch: Watches the
theme-config
directory for changes. When a change is detected, automatically recompilestheme.json
(creating a backup the first time in each session).
npx @builtnorth/wp-theme-json-compiler compile --theme-path=wp-content/themes/your-theme
npx @builtnorth/wp-theme-json-compiler split --theme-path=wp-content/themes/your-theme
npx @builtnorth/wp-theme-json-compiler watch --theme-path=wp-content/themes/your-theme
- If
--theme-path
is omitted, the current working directory is used.
Add to your root package.json
scripts:
"theme-json:compile": "wp-theme-json-compiler compile --theme-path=wp-content/themes/your-theme",
"theme-json:split": "wp-theme-json-compiler split --theme-path=wp-content/themes/your-theme",
"theme-json:watch": "wp-theme-json-compiler watch --theme-path=wp-content/themes/your-theme"
- By default, operates on
theme.json
andtheme-config
in the current working directory. - Use
--theme-path
to specify a custom theme directory.
Before overwriting your existing theme.json
, the compiler automatically creates a backup named theme.backup.json
in the same theme directory. This occurs every time you run the compile
command, and once per session when using the watch
command (the first time a change is detected).
- The backup file is always named
theme.backup.json
and will be overwritten on subsequent runs. - This helps prevent accidental data loss. To restore, simply rename or copy
theme.backup.json
back totheme.json
. - Always verify your changes and keep your own version control backups for extra safety.
Thanks to Nick Diego's article on managing theme.json files that came up in search results when looking into spitting up a monolithic theme.json file.
This tool is provided "as is" without warranty of any kind, express or implied. Use at your own risk. Tool will override currenth theme.json files, so please understand that and/or have a backup. The authors and contributors are not responsible for any damages or liabilities arising from the use of this library. Always test thoroughly in your specific environment before deploying to production.
GNU General Public License version 2 (or later) (GPLv2)