A modular theme.json compiler for WordPress themes.
⚠️ WarningThe
compileandwatchcommands will overwrite yourtheme.jsonfile 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.jsoninto 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.jsonfile into modular JavaScript files in thetheme-configdirectory. This makes it easier to manage and edit theme settings in a structured way. - compile: Compiles all modular files from the
theme-configdirectory back into a singletheme.jsonfile. Automatically creates a backup of the existingtheme.jsonbefore overwriting. - watch: Watches the
theme-configdirectory 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-pathis 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.jsonandtheme-configin the current working directory. - Use
--theme-pathto 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.jsonand will be overwritten on subsequent runs. - This helps prevent accidental data loss. To restore, simply rename or copy
theme.backup.jsonback 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)