bricks_create_component
Overview
Creates a reusable Bricks Component with configurable properties that connect to internal elements via ref names. Components are the cornerstone of maintainable Bricks sites — they define an element structure once and allow per-instance customization through property connections.
This is the most important tool for avoiding the #2 quality issue: duplicated element structures. Any card, testimonial, feature box, or repeating pattern that appears 3+ times MUST be a component. Each instance uses a single element with componentId and properties instead of duplicating dozens of elements.
Properties map to internal element settings via ref names, so changing « Title » on an instance updates the heading text inside that component instance automatically.
Key Features
When to Use
When any element group (card, feature box, testimonial) will appear 3+ times
When building category cards, service cards, team member cards, pricing cards
Before building sections with repeated patterns — create the component FIRST
When the server raises a "Component Alert" warning about duplicated structures
Global classes referenced by component elements must already exist
Understand the element types and settings format (see CLAUDE.md Element JSON Format)
When NOT to Use
When a pattern appears fewer than 3 times (use global classes instead)
For content that must stay synchronized across all pages — use bricks_create_global_element instead
Parameters
Warning: Undefined array key "param_enum_values" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 28
labelstringREQUIREDWarning: Undefined array key "param_enum_values" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 28
categorystringoptionalWarning: Undefined array key "param_enum_values" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 28
elementsobjectREQUIREDWarning: Undefined array key "param_enum_values" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 28
propertiesarrayoptionalCode Examples
Category Card component with image, icon, title, and description
Creates a reusable card component with 4 configurable properties. Each instance in a section becomes a single element instead of duplicating the entire structure.
bricks_create_component({
label: "Category Card",
category: "cards",
elements: {
type: "div", ref: "card-root",
settings: { "_background": { "color": { "hex": "#ffffff" } }, "_border": { "radius": { "top": "12", "right": "12", "bottom": "12", "left": "12" } }, "_overflow": "hidden" },
children: [
{ type: "div", children: [
{ type: "image", ref: "card-image", settings: { "_objectFit": "cover" } }
]},
{ type: "div", settings: { "_padding": { "top": "20", "right": "20", "bottom": "20", "left": "20" } }, children: [
{ type: "icon", ref: "card-icon", settings: { "_typography": { "font-size": "28px" } } },
{ type: "heading", ref: "card-title", settings: { "tag": "h3" }, globalClasses: ["heading-card"] },
{ type: "text-basic", ref: "card-desc", globalClasses: ["text-body"] }
]}
]
},
properties: [
{ label: "Image", connections: { "card-image": ["image"] } },
{ label: "Icon", connections: { "card-icon": ["icon"] } },
{ label: "Title", connections: { "card-title": ["text"] } },
{ label: "Description", connections: { "card-desc": ["text"] } }
]
}){
"success": true,
"data": {
"id": "abc123",
"label": "Category Card",
"element_count": 6,
"properties": [
{ "label": "Image", "connections": { "card-image": ["image"] } },
{ "label": "Icon", "connections": { "card-icon": ["icon"] } },
{ "label": "Title", "connections": { "card-title": ["text"] } },
{ "label": "Description", "connections": { "card-desc": ["text"] } }
]
}
}
// Then use in sections:
{ "type": "div", "componentId": "abc123", "ref": "cat-1", "properties": {
"Image": { "url": "https://...", "id": 34 },
"Icon": { "icon": "fas fa-truck", "library": "fontawesome" },
"Title": "Fourgons utilitaires",
"Description": "De 4m3 a 15m3"
}}Common Mistakes
// 6 cards x 10 elements = 60 duplicated elements
{ "type": "div", "settings": { "_background": ..., "_border": ... },
"children": [
{ "type": "image", "settings": { "image": {...} } },
{ "type": "heading", "settings": { "text": "Card 1", "tag": "h3" } },
{ "type": "text-basic", "settings": { "text": "Description..." } }
]
}
// Repeated 6 times with different content// 1 component + 6 instances = 7 elements total
bricks_create_component({ label: "Card", elements: {...}, properties: [...] })
// Returns { id: "abc123" }
// Then per instance:
{ "type": "div", "componentId": "abc123", "properties": {
"Title": "Card 1", "Description": "Description..."
}}// No ref on heading — property connection will fail
{ type: "heading", settings: { "tag": "h3" } }
// properties: [{ label: "Title", connections: { "card-title": ["text"] } }]// ref matches the connections key
{ type: "heading", ref: "card-title", settings: { "tag": "h3" } }
// properties: [{ label: "Title", connections: { "card-title": ["text"] } }]// Phase 4: Build 6 identical cards manually, THEN realize they should be a component// Phase 2: Create component FIRST
bricks_create_component({...})
// Phase 4: Use componentId in sectionsTips & Warnings
Critical rule: The Component-First Pattern is the #2 most important quality rule (after using global classes). Any repeated pattern appearing 3+ times MUST be a component.
When to use components vs global elements: Components have configurable properties per instance (different title, image, etc.). Global elements are identical everywhere — editing one updates all instances site-wide. Use components for cards, features, testimonials. Use global elements for shared CTAs, banners, or notices.
Property connections: The connections map uses ref_name as the key and an array of setting keys as the value. For example, { "card-image": ["image"] } maps the property value to the image setting of the element with ref: "card-image".
Payload size: Keep component element trees under 30-40 elements to avoid 502 errors. For very complex components, consider splitting into nested sub-components.