bricks_update_element
Overview
Update settings of a specific element on a Bricks page. Performs a deep merge — only the provided settings keys are changed, while all other existing settings remain untouched. This is the primary tool for fine-tuning individual elements after they are placed on a page.
Can update text content, CSS styles, responsive breakpoints, global class assignments, and any other element setting. The deep merge means you can update just one typography property without losing the others. Also supports assigning or removing global classes by name.
Key Features
When to Use
You want to update CSS styles or add responsive breakpoints to an existing element
You need to assign or remove global classes on an element
You are fixing issues found by bricks_validate_page (e.g., adding alt text to images)
You need to update a few elements without rebuilding the whole section
When NOT to Use
You want to replace an entire section (use bricks_replace_section instead)
You need to add a new element that does not exist yet (use bricks_insert_element instead)
You want to move an element to a new position (use bricks_move_element instead)
Parameters
page_idnumberREQUIREDelement_idstringREQUIREDsettingsobjectREQUIREDglobalClassesarrayoptionalcontent_areastringoptionalcontent Values: content, header, footerCode Examples
Update heading text and add a class
Change the text of a heading and assign a global class to it.
bricks_update_element({
page_id: 42,
element_id: "d4e5f6",
settings: {
"text": "Updated Heading Text"
},
globalClasses: ["heading-section"]
}){
"success": true,
"element": {
"id": "d4e5f6",
"type": "heading",
"settings": {
"tag": "h2",
"text": "Updated Heading Text"
},
"_cssGlobalClasses": ["resolved-class-id"]
}
}Add responsive typography to an existing element
Add mobile font size without losing existing desktop typography settings.
bricks_update_element({
page_id: 42,
element_id: "d4e5f6",
settings: {
"_typography:mobile_portrait": {
"font-size": "28px"
}
}
}){
"success": true,
"element": {
"id": "d4e5f6",
"settings": {
"_typography": { "font-size": "48px", "font-weight": "700" },
"_typography:mobile_portrait": { "font-size": "28px" }
}
}
}Common Mistakes
bricks_update_element({ page_id: 42, element_id: "a1", settings: { text: "A" } })
bricks_update_element({ page_id: 42, element_id: "b2", settings: { text: "B" } })
bricks_update_element({ page_id: 42, element_id: "c3", settings: { text: "C" } })
// 3 API calls, 3 DB writesbricks_bulk_update_elements({
page_id: 42,
updates: [
{ element_id: "a1", settings: { text: "A" } },
{ element_id: "b2", settings: { text: "B" } },
{ element_id: "c3", settings: { text: "C" } }
]
})
// 1 API call, 1 DB write// Expecting this removes _border
bricks_update_element({
element_id: "a1",
settings: { "_typography": { "color": { "hex": "#000" } } }
})
// _border is still there (deep merge)// Deep merge: existing _border stays
// Only _typography.color is updated
// Other _typography props preserved tooTips & Warnings
Deep merge behavior: Only the keys you provide are changed. If an element has _typography with 5 properties and you update with { « _typography »: { « color »: { « hex »: « #000 » } } }, only the color changes — font-size, font-weight, etc. are preserved.
Global classes replace: Unlike settings (merge), globalClasses replaces the entire class list. To add a class without removing existing ones, first read the current classes, then pass the combined list.
Use bricks_bulk_update_elements for multiple updates: For 3+ elements, the bulk tool is significantly more efficient (single API call and DB write).