bricks_delete_section

Phase 4BeginnerDestructiveComplexity: 3/10
Delete a section and all its children

Overview

Delete a section and all its child elements from a Bricks page. Identifies the section by its root element ID and recursively removes all descendants. The remaining sections on the page are unaffected and maintain their positions.

Use bricks_get_page_content first to find the section ID you want to remove. This is a destructive operation — the section content cannot be recovered through the API (though WordPress revisions may still have it).

Key Features

Recursive Deletion
Removes the section and ALL its descendants (containers, elements, nested children) in one call.
Safe for Other Sections
Only the targeted section and its children are removed. Other sections on the page remain untouched.

When to Use

You need to remove an unwanted section from a page
You are cleaning up duplicate or test sections
A section needs to be removed as part of a page redesign
You want to reduce the page to fewer sections
Prerequisites
The page and section must exist. Use bricks_get_page_content in summary mode to find the root section element ID. The section_id must be a root-level element (parent: 0) of type "section".

When NOT to Use

You want to replace a section with new content (use bricks_replace_section instead -- more efficient in one call)
You only need to remove a single element within a section (use bricks_delete_element instead)
You want to reorder sections without removing any (use bricks_reorder_sections instead)

Parameters

2 Total Parameters2 Required
page_idnumberREQUIRED
Page ID containing the section to delete.
section_idstringREQUIRED
The 6-char Bricks element ID of the root section element to delete.

Code Examples

Delete a section from a page

Find the section ID, then remove it along with all its child elements.

JSON
// Step 1: Find section IDs
bricks_get_page_content({ page_id: 42, mode: "summary" })
// Find the section to remove: id "a1b2c3"

// Step 2: Delete the section
bricks_delete_section({
  page_id: 42,
  section_id: "a1b2c3"
})
Response
{
  "success": true,
  "message": "Section a1b2c3 deleted from page 42",
  "elements_removed": 12
}

Common Mistakes

Deleting a section then trying to use its element IDs
All element IDs within the deleted section become invalid after deletion. Any subsequent calls referencing those IDs will fail.
Wrong
bricks_delete_section({ page_id: 42, section_id: "a1b2c3" })
bricks_update_element({ page_id: 42, element_id: "d4e5f6", ... })
// d4e5f6 was inside the deleted section!
Correct
bricks_delete_section({ page_id: 42, section_id: "a1b2c3" })
// Now add a new section if needed
bricks_add_section({ page_id: 42, section: { ... } })

Tips & Warnings

Tips & Warnings

Irreversible via API: There is no undo. WordPress may have the previous version in its revision history, which you can restore with bricks_restore_revision.

Use replace instead of delete + add: If you want to swap a section for a new one, use bricks_replace_section instead of deleting and then adding — it is more efficient and maintains position.

Return Values

FieldTypeDescription
successbooleanWhether the deletion was successful.
messagestringConfirmation message with section ID and page ID.
elements_removednumberTotal number of elements removed (section + all descendants).

Related Tools

Technical Details

Tool ID
bricks_delete_section
API Endpoint
/bricks-mcp/v1/pages/{page_id}/sections/{section_id}
HTTP Method
DELETE
Namespace
pages-elements
Source File
pages/sections.ts
Version
1.0
Min Bricks Version
1.9
Requires Auth
Yes

Changelog

v1.0
Initial release with recursive section deletion.
20250101