wp_replace_section
Replace, insert, or delete ONE top-level section without rewriting the whole page — SAFER than wp_update_page for large pages (every other section is preserved exactly, so you can't accidentally drop content). Target the section by index (0-based, from wp_get_page outline) or top-level node_id. sections is the same native spec wp_update_page takes. op: replace (default) | insert_before | insert_after | delete | append. dry_run=true previews the section counts. Round-trip validated, write-gated.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| op | No | replace (default) | insert_before | insert_after | delete | append | |
| index | No | 0-based top-level section index (or use node_id) | |
| atomic | No | Editor V4 ATOMIC spec (JSON array) for sites where Editor V4 is active: [{type: heading|paragraph|image|button|div|flex|grid|tabs, …}]; tabs = {type:"tabs", tabs:[{label, children:[…]}], active:0}. XeoRank emits valid V4 JSON (e-tabs/e-tabs-menu/e-tab/e-tabs-content-area/e-tab-content, typed envelopes, ids). wp_widget_schema("e-tabs") and wp_section_recipes("v4-tabs") show the shape. Raw elements also accepted via elementor_data/elements. | |
| dry_run | No | Preview section counts without writing. Default false. | |
| node_id | No | A top-level element id from wp_get_page outline (or use index) | |
| post_id | Yes | The page/post ID | |
| site_id | Yes | The WordPress site ID | |
| elements | No | RAW top-level element JSON, spliced in VERBATIM — use this for Editor V4 Atomic (e-flexbox, e-div-block, e-heading, ...). The `sections` spec below always emits the classic CONTAINER model and cannot express atomic at all, so appending atomic through it silently downgrades it. Verbatim also means you can assemble a large page one section at a time instead of resending the whole thing. | |
| sections | No | JSON array of native section objects (required unless op=delete) | |
| allow_widget_loss | No | op=replace on a `sections` spec: required (true) if the existing section has a widget type the spec builder cannot recreate (409 would_destroy_unsupported_widgets names them first, without this). Not needed for `elements` (verbatim) -- that path never runs this guard, since you are supplying the full replacement yourself. |