bricks_delete_element

Phase 4BeginnerDestructiveComplexity: 2/10
Remove an element and its children

Overview

Delete an element and all its children from a Bricks page. The parent element’s children array is automatically updated to maintain valid structure. This removes a single element (and its descendants) from within a section, unlike bricks_delete_section which removes an entire root-level section.

After deletion, the parent container still exists with its remaining children. If you delete the only child of a container, the container remains but will be empty.

Key Features

Recursive Child Removal
Removes the element and all its descendants. Deleting a container removes all its children, grandchildren, etc.
Parent Auto-Update
The parent container's children array is automatically cleaned up to maintain valid structure.
Content Area Aware
Works across main content, header overrides, and footer overrides.

When to Use

You need to remove a specific element from within a section (a card from a grid, a button, etc.)
You want to clean up unwanted elements without removing the entire section
You are fixing layout issues by removing elements that cause problems
An element needs to be replaced -- delete it first, then insert a new one with bricks_insert_element
Prerequisites
The page and element must exist. Use bricks_get_page_content to find the element ID and verify it is the correct element before deleting. Deletion is not reversible through the API.

When NOT to Use

You want to remove an entire section and all its children (use bricks_delete_section instead)
You want to replace an element with a new one in the same operation (no atomic replace -- delete then insert)
You want to hide an element conditionally (use bricks_set_element_conditions instead)
You want to move the element, not delete it (use bricks_move_element instead)

Parameters

3 Total Parameters2 Required1 Optional
page_idnumberREQUIRED
Page ID containing the element to delete.
element_idstringREQUIRED
The 6-char Bricks element ID to delete.
content_areastringoptional
Content area where the element resides.
Default: content Values: content, header, footer

Code Examples

Delete a card from a grid

Remove a specific card element from a grid container. The grid and other cards remain.

JSON
// Step 1: Find the element to delete
bricks_get_page_content({ page_id: 42, mode: "summary" })
// Find card with id: "card03"

// Step 2: Delete it
bricks_delete_element({
  page_id: 42,
  element_id: "card03"
})
Response
{
  "success": true,
  "deleted_count": 4,
  "deleted_ids": ["card03", "icon03", "heading03", "text03"]
}

Delete an element from a header override

Remove an element from the header content area of a page.

JSON
bricks_delete_element({
  page_id: 42,
  element_id: "extra-btn",
  content_area: "header"
})
Response
{
  "success": true,
  "deleted_count": 1,
  "deleted_ids": ["extra-btn"]
}

Common Mistakes

Deleting a container when you only wanted to remove one child
Deleting a container removes ALL its children. Make sure you are targeting the correct element, not its parent container.
Wrong
bricks_delete_element({
  element_id: "grid-container"
})
// Removes the entire grid + all cards!
Correct
bricks_delete_element({
  element_id: "card-to-remove"
})
// Only removes the specific card
Using delete_element when delete_section is more appropriate
For root-level sections (parent: 0), use bricks_delete_section. bricks_delete_element works on any element but bricks_delete_section is semantically clearer for top-level sections.
Wrong
bricks_delete_element({
  element_id: "section-root-id"
})
// Works but not semantically clear
Correct
bricks_delete_section({
  page_id: 42,
  section_id: "section-root-id"
})
// Clear intent: removing a section

Tips & Warnings

Tips & Warnings

Verify before deleting: Use bricks_get_page_content in summary mode to verify the element type and children before deleting. Removing the wrong element can break page layout.

Cascading deletion: All children are removed recursively. If you delete a div with 10 child elements, all 11 elements are removed.

Not undoable via API: Deleted elements cannot be recovered through the API. WordPress revision history may contain the previous state, restorable with bricks_restore_revision.

Return Values

FieldTypeDescription
successbooleanWhether the deletion was successful.
deleted_countnumberTotal number of elements removed (target + all descendants).
deleted_idsarrayList of all element IDs that were removed.

Related Tools

Technical Details

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

Changelog

v1.0
Initial release with recursive child deletion and parent auto-update.
20250101