Write a theme file
write_theme_fileWrite or replace a WordPress theme file safely: defaults to draft themes to protect your live site, and syntax-checks PHP before saving to prevent fatal errors.
Instructions
Create or overwrite a theme file, replacing its entire contents. Refuses to write to a live active theme by default — work in a draft (create_draft_theme) so the site stays untouched until you publish. PHP is syntax-checked before it is saved, so a parse error is reported rather than fataling the site.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path relative to the theme root, e.g. "template-parts/hero.php". Parent directories are created as needed. | |
| theme | No | Theme stylesheet or draft id. Defaults to the active draft if there is one. | |
| content | Yes | Full file contents. | |
| site_id | No | Which configured WordPress site to act on. Optional — with a single site configured it is used automatically; with several, the default site is used unless you name one. Run list_sites for valid ids. | |
| allow_live_theme | No | Permit writing directly into the live active theme. Strongly discouraged — use a draft. |