bricks_insert_element

Phase 4IntermediateComplexity: 5/10
Insert a single element into an existing container

Overview

Insert an element (with optional children) into an existing container on a Bricks page. Unlike bricks_add_section which adds at the page root level, this tool adds elements INSIDE an existing element. Uses the same simplified JSON format as bricks_add_section.

This is essential for adding content to existing sections without replacing them entirely. For example, adding a new card to an existing grid, or appending a CTA button to an existing container. Works across all content areas (main content, header overrides, footer overrides).

Key Features

Nested Insertion
Inserts elements inside any existing container, not just at the page root level. Essential for building sections incrementally.
Position Control
Append to end, prepend to beginning, or insert at a specific index among the container's existing children.
Full Element Tree Support
The inserted element can have its own children, creating a full subtree within the existing container.
Content Area Aware
Works across all three content areas: main content, header overrides, and footer overrides.

When to Use

You need to add elements inside an existing container without replacing the whole section
You want to append a new card to an existing grid or card row
You need to add a CTA button or additional text to an existing section
A section was too large for one bricks_add_section call -- add the remaining elements via insert
You are building a section incrementally by adding elements to containers
Prerequisites
The page and parent container must exist. Use bricks_get_page_content to find the parent element ID. The parent must be a container-type element (section, container, block, div, or any element that can hold children).

When NOT to Use

You want to add a new root-level section to the page (use bricks_add_section instead)
You want to replace an entire section (use bricks_replace_section instead)
You need to move an existing element to a different container (use bricks_move_element instead)
You want to update settings of an existing element (use bricks_update_element instead)

Parameters

6 Total Parameters3 Required3 Optional
page_idnumberREQUIRED
Page ID containing the parent element.
parent_idstringREQUIRED
The 6-char Bricks element ID of the container to insert into.
elementobjectREQUIRED
The element tree to insert. Same hierarchical JSON format as bricks_add_section sections.
positionstringoptional
Where to insert among the container's children: append (end) or prepend (beginning).
Default: append Values: append, prepend
position_indexnumberoptional
Insert at a specific index among siblings (0-based). Overrides position if provided.
content_areastringoptional
Content area where the parent element resides.
Default: content Values: content, header, footer

Code Examples

Add a card to an existing grid container

Insert a new card element into an existing 3-column grid on the page.

JSON
// Step 1: Find the grid container ID
bricks_get_page_content({ page_id: 42, mode: "summary" })
// Grid container has id: "grid123"

// Step 2: Insert a new card
bricks_insert_element({
  page_id: 42,
  parent_id: "grid123",
  element: {
    type: "div",
    ref: "new-card",
    settings: {},
    globalClasses: ["card"],
    children: [
      { type: "icon", settings: { icon: "fas fa-globe" } },
      { type: "heading", settings: { tag: "h3", text: "Global Reach" }, globalClasses: ["heading-card"] },
      { type: "text-basic", settings: { text: "Available worldwide." }, globalClasses: ["text-body"] }
    ]
  },
  position: "append"
})
Response
{
  "success": true,
  "message": "Element inserted into grid123 on page 42",
  "element_ids": { "new-card": "k1l2m3" },
  "elements_count": 4
}

Prepend a heading inside a container

Add a section label before existing content in a container.

JSON
bricks_insert_element({
  page_id: 42,
  parent_id: "cnt456",
  element: {
    type: "text-basic",
    ref: "section-label",
    settings: { text: "OUR SERVICES" },
    globalClasses: ["section-label"]
  },
  position: "prepend"
})
Response
{
  "success": true,
  "element_ids": { "section-label": "n4o5p6" },
  "elements_count": 1
}

Common Mistakes

Using bricks_add_section when you need to insert into an existing container
bricks_add_section adds at the page root level (new section). To add inside an existing element, use bricks_insert_element with the parent container ID.
Wrong
bricks_add_section({
  page_id: 42,
  section: { type: "heading", settings: { text: "New" } }
})
// Creates a new section, not inside existing container
Correct
bricks_insert_element({
  page_id: 42,
  parent_id: "existing-container-id",
  element: { type: "heading", settings: { text: "New" }, globalClasses: ["heading-card"] }
})
Inserting into a non-container element
The parent_id must point to an element that can hold children (section, container, block, div). Content elements like heading, text-basic, or button cannot be parents.
Wrong
bricks_insert_element({
  parent_id: "heading-id",  // headings cannot have children!
  element: { type: "text-basic", ... }
})
Correct
bricks_insert_element({
  parent_id: "container-id",  // container can hold children
  element: { type: "text-basic", ... }
})

Tips & Warnings

Tips & Warnings

Splitting large sections: If bricks_add_section would exceed the 30-40 element limit, create the section with core structure first, then use bricks_insert_element to add remaining elements into specific containers.

Finding parent IDs: Use bricks_get_page_content in summary mode to find container element IDs. Or use bricks_get_element_by_ref if you set a ref name when creating the container.

Content area matters: If the parent element is in the header override, set content_area to « header ». The tool will not find the element if you use the wrong content area.

Return Values

FieldTypeDescription
successbooleanWhether the element was inserted successfully.
element_idsobjectMap of ref names to generated element IDs.
elements_countnumberNumber of elements inserted (including children).

Related Tools

Technical Details

Tool ID
bricks_insert_element
API Endpoint
/bricks-mcp/v1/pages/{page_id}/elements/{parent_id}/children
HTTP Method
POST
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 nested insertion, position control, and content area support.
20250101