Swap one block on a page without resending the page

ContentIntermediate~10 minUpdated

Before you start

Plugin version 1.10.0 or newer. The two block type reads and Replace block are off until you switch them on in the Abilities tab; Replace block is a write, so enable it for the write pass. The agent needs edit access to the page. Pages owned by one of ten page builders (Elementor, Divi, Beaver Builder, Avada, Visual Composer, Oxygen, Breakdance, Brizy, Bricks or WPBakery) are refused, because the builder controls how that page is stored and shown.

Long pages are where full-page rewrites go wrong. You want one section changed, the old media and text pair in the middle of the services page, and the usual way an agent does that is by sending the whole page back with the change folded in. Every other block rides along on that trip, which is a lot to trust for one section.

Replace block changes one block, picked by its position, and leaves the rest of the page out of the write. This recipe reads the page, agrees on the block with you, and swaps only that one.

The prompt
On our [Services] page (id [57]) I want to replace one section. It is the
[media and text block about consulting], somewhere in the middle.
Read the page as raw block markup and list the top-level blocks in order,
with their position and block name, so we agree which one it is.
The replacement is a [core/group] block holding [a heading, a short
paragraph and a button to /contact/]. Check that every block you plan to
use is registered on this site, and read the attributes it accepts, so
the markup is valid.
Show me the current block and the exact new markup side by side. Do not
save until I say go. When I do, replace only that block, passing the
block name you expect at that position, and read the page again just before
the write, because the check compares the block name only. Keep the old block markup in your reply, and tell me about
any content warnings the write returns.

Why this is safe to run

The page read and both block type reads change nothing, and they come first. You agree on the exact block by position and name, and you see the exact markup that will take its place, before anything is saved.

The write is one Replace block call. The plugin leaves the other blocks’ parsed attributes and HTML as they were, and passing the expected block name means a block of a different type at that position is refused. The check compares the block name only, so read the page again just before writing if it may have changed. If the page’s existing markup cannot be saved back cleanly, for example a block with broken attribute JSON, the call refuses too, and Update post is the tool for that page. Replace block is off until you enable it, it is checked against the edit access of the user the agent is bound to, it lands in the Activity Log, and the earlier block stays in the chat because the prompt keeps the old markup. The swap is recorded in the Changes tab as well, which can revert it until the page is edited again.

Not sure what the page is made of yet? Run inspect a page’s block structure first.

Already connected? You do not have to paste this. Ask your agent for the “swap one block on a page” recipe, or describe the section you want replaced, and it runs the same read-first flow on your own site.

How it works

  1. Read the page as raw block markup and list its top-level blocks with their positions.
  2. Confirm the block you want to swap by position and block name.
  3. Check that the replacement block type is registered and read the attributes it accepts.
  4. Show the old block and the exact new markup side by side, and wait for your approval.
  5. Replace only that block, refusing if the block at that position is no longer the expected one.

Questions

How does the agent find the right block?
By path: the block's position among the top-level blocks, then among that block's inner blocks, counting only real blocks. So [2, 0] is the first block inside the third top-level block. The prompt has the agent read the page first and confirm the position with you.
What if someone edited the page in between?
The prompt has the agent pass the block name it expects at that position. If a block of a different type sits there now, the write is refused. The check compares the block name only, so a different block of the same type would not be caught, which is why the agent reads the page again just before it writes.
Can the new markup hold more than one block?
The replacement is one block. To put several pieces in its place, wrap them in a single container block such as a group, which is what this recipe does.