Build a Whole Menu in One Command
wp_build_menuBuild an entire WordPress menu with submenus, item ordering, and theme-location assignment from one structured spec.
Instructions
Create an entire navigation menu — nested submenus, ordering, and theme-location assignment — from one structured spec. Ideal for rebuilding a site's primary navigation by command.
Each item links to a page (page_id) OR a custom URL (url), OR neither (a non-linking dropdown parent that just holds children). Children create submenus. Order follows array order.
Args:
name (string): Menu name to create.
locations (string[]): Optional theme locations, e.g. ['primary'].
items: ordered array of { title, page_id?, url?, children?[] }.
response_format (enum): markdown | json.
Example items: [ { "title": "Concerts", "children": [ { "title": "This Season", "page_id": 123 }, { "title": "Tickets", "page_id": 3285 } ]}, { "title": "Donate", "url": "/support/donate/" } ]
Returns: { menu_id, items_created, locations }. Note: creates a NEW menu; it does not merge into an existing one. Use wp_list_menus / wp_delete_menu first if replacing.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Menu name to create, e.g. 'Primary Navigation'. | |
| items | Yes | Ordered top-level items, each optionally with nested children (submenus). | |
| locations | No | Theme menu locations to assign, e.g. ['primary']. | |
| response_format | No | Output format: 'markdown' for human-readable, 'json' for machine-readable. | markdown |