Rebuild a block-theme navigation menu

MenusIntermediate~10 min

Before you start

Plugin version 1.12.0 or newer on a block theme, from a connection whose user holds the edit-theme-options capability. Update navigation is off by default. A classic theme keeps its menus elsewhere; use the menu tools for those.

On a block theme, the menu in your header is a Navigation block, and its links live in a navigation post that the Site Editor manages. Editing the classic menus under Appearance does not reach it, which is why a menu change can look like it never happened. Rebuilding the header links by hand in the Site Editor is fiddly, especially with dropdowns.

This prompt reads the real navigation, agrees the new structure with you, and writes it once.

The prompt
I want to rebuild the main header menu on this site. The new structure:
[Home (/), Services (/services/) with Web design (/services/web-design/)
and Hosting (/services/hosting/) under it, Blog (/blog/), Contact (/contact/)]
First check with get-active-theme that this is a block theme; if it is not,
stop and tell me to use the classic menu tools. List the navigation menus with
list-navigations and show me each one's title, id and link tree, plus anything
under other_blocks. Ask me which one is the header menu.
Check every internal link in my structure against the published pages with
get-pages and flag any that do not match. Then show me the current tree beside
the new one, and list what the replace will drop: other_blocks, and per-link
settings such as open in a new tab. Wait for my go. Then send the full tree in
one update-navigation call, read it back with list-navigations, and keep the
old tree in your reply.

Why this is safe to run

Everything before the write is a read. You see the current tree, the blocks the replace would remove, and every link checked against a published page, before you approve.

The write is bounded. It takes a label and a URL per item, nested up to three levels and 100 items in all, and an empty list is refused. A URL must be an http, https, mailto or tel link, a path starting with /, or an anchor starting with #; anything else is refused. A navigation owned by a page builder is refused too.

Update navigation is a replace, so the old tree from the first read is your copy. It is off by default, needs the edit-theme-options capability, runs as the user you bound the agent to, and lands in the Activity Log.

For classic menus on a classic theme, use manage and rebuild navigation menus instead.

Already connected? Ask your agent for the “rebuild a block-theme navigation menu” recipe, describe the links you want, and it runs the same read-first flow on your own site.

How it works

  1. Confirm the active theme is a block theme.
  2. List the navigation menus with their full link trees and any blocks the tree cannot show.
  3. Check the pages you want to link and draft the new tree with you.
  4. Show the old and new tree side by side, including what the replace drops, and wait for approval.
  5. Replace the navigation in one call and read it back.

Questions

Why do my classic menu changes not show on a block theme?
A block theme's header shows a Navigation block, and that block reads a navigation post, not the classic menus under Appearance. List navigations and Update navigation work on those navigation posts. Classic menus are still read and edited with the menu tools.
What does the replace keep?
Only the labels, URLs and nesting you send. The whole navigation is replaced, and each link is saved as a plain custom link, so per-link settings such as open in a new tab, rel, CSS classes and a link's binding to a page are not kept. Blocks that list-navigations names under other_blocks, such as a page list or a search box, are removed too.
How do I undo it?
Navigation edits are not in the Changes tab. The read at the start holds the old link tree, so the agent can send it back with another Update navigation call, though per-link settings and other blocks do not come back that way. When the site keeps revisions, WordPress saves each new version as a revision, so an earlier version can be restored only if it was already kept as one.