bricks_create_custom_element
Overview
Registers a custom Bricks element via PHP in the child theme. Custom elements extend the Bricks element panel with completely bespoke functionality, rendered by PHP templates with full access to WordPress functions and element settings.
Controls define the settings panel that users see in the Bricks builder (text fields, color pickers, repeaters, etc.). The render_html is a PHP template that receives $settings and $element variables and outputs the HTML. Optionally, provide CSS for default styling and a Vue.js builder_template for WYSIWYG editing in the builder.
Use custom elements when built-in Bricks elements and components are insufficient — for example, complex pricing cards with conditional logic, custom post type displays, or third-party API integrations.
Key Features
When to Use
For complex elements with conditional rendering logic (e.g., highlighted pricing card)
When you need PHP access to WordPress functions (WP_Query, get_posts, etc.)
For elements that integrate with third-party APIs or plugins
When you need a nestable container element (set nestable=true)
Understanding of PHP templating and WordPress functions
Knowledge of Bricks control types (text, textarea, number, select, checkbox, color, image, repeater, etc.)
When NOT to Use
When a Component (bricks_create_component) with properties is sufficient
For simple card layouts that do not require PHP logic
When global classes and standard element types cover the need
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
namestringREQUIREDWarning: 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
categorystringREQUIREDWarning: 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
iconstringoptionalWarning: 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
controlsarrayREQUIREDWarning: 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
render_htmlstringREQUIREDWarning: 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
cssstringoptionalWarning: 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
scriptsarrayoptionalWarning: 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
nestablebooleanoptionalfalseWarning: 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
builder_templatestringoptionalCode Examples
Pricing Card custom element with PHP rendering
Creates a custom pricing card with plan name, price, period, features repeater, CTA button, and highlighted state. Uses PHP conditionals for the highlighted variant.
bricks_create_custom_element({
name: "pricing-card",
label: "Pricing Card",
category: "custom",
controls: [
{ key: "plan_name", type: "text", label: "Plan Name", default: "Starter" },
{ key: "price", type: "text", label: "Price", default: "$29" },
{ key: "period", type: "text", label: "Period", default: "/month" },
{ key: "features", type: "repeater", label: "Features" },
{ key: "cta_text", type: "text", label: "Button Text", default: "Get Started" },
{ key: "highlighted", type: "checkbox", label: "Highlighted", default: false }
],
render_html: "<div class="pricing-card <?php echo !empty($settings['highlighted']) ? 'highlighted' : ''; ?>">n <h3><?php echo esc_html($settings['plan_name']); ?></h3>n <div class="price">n <span class="amount"><?php echo esc_html($settings['price']); ?></span>n <span class="period"><?php echo esc_html($settings['period']); ?></span>n </div>n <ul>n <?php foreach ($settings['features'] ?? [] as $f): ?>n <li><?php echo esc_html($f['text'] ?? ''); ?></li>n <?php endforeach; ?>n </ul>n <a href="#" class="btn"><?php echo esc_html($settings['cta_text']); ?></a>n</div>",
css: ".pricing-card { padding: 40px 30px; border-radius: 12px; background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,0.05); text-align: center; }n.pricing-card.highlighted { border: 2px solid var(--bricks-color-primary); transform: scale(1.05); }n.pricing-card .price .amount { font-size: 48px; font-weight: 700; }n.pricing-card .price .period { font-size: 16px; color: #888; }n.pricing-card ul { list-style: none; padding: 0; margin: 24px 0; }n.pricing-card li { padding: 8px 0; border-bottom: 1px solid #eee; }"
}){
"success": true,
"data": {
"name": "pricing-card",
"file": "/wp-content/themes/bricks-child/bricks-mcp/element-pricing-card.php",
"label": "Pricing Card"
}
}Common Mistakes
// Creating a custom FAQ element from scratch
bricks_create_custom_element({ name: "faq-section", ... })// Use the native accordion element instead
{ "type": "accordion", "settings": { "accordions": [...], "faqSchema": true } }<h3><?php echo $settings['title']; ?></h3><h3><?php echo esc_html($settings['title']); ?></h3><?php foreach ($settings['features'] as $f): ?><?php foreach ($settings['features'] ?? [] as $f): ?>Tips & Warnings
Child theme required: Custom elements are saved as PHP files in the child theme’s bricks-mcp/ directory. A Bricks child theme must be active.
Control types: The 12 supported types are: text, textarea, number, select, checkbox, color, image, repeater, typography, code, link, and rich-text. Use the appropriate type for the best editing experience.
Nestable elements: Set nestable: true to create container elements that accept child elements. The render_html should include a child rendering placeholder where nested content will appear.
Builder template: For a better editing experience, provide a Vue.js builder_template that mirrors the PHP rendering. This enables WYSIWYG editing with live preview in the Bricks builder.