Builds and debugs custom PHP Bricks elements with registration, controls, rendering, assets, and Builder updates.
Ships in bricks. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A custom element is a PHP class extending \Bricks\Element that adds a new element type to the Bricks builder's element panel. Ship it through a child theme or plugin.
Use a native element when it already provides the requested behavior. For reusable native layouts with editable content or variants, prefer bricks-components. Create a custom element when new rendering or behavior is needed. Keep one coherent purpose per element; variants of the same widget can share one.
Expose the controls users need to edit the result, and load assets for actual instances rather than assuming a particular page type. Preserve legacy instances and revisions when replacing an existing implementation. These are authoring recommendations, not a requirement to split every existing element.
<?php
namespace MyTheme\Bricks;
if ( ! defined( 'ABSPATH' ) ) exit;
class Pricing_Card extends \Bricks\Element {
public $category = 'general'; // Element panel category
public $name = 'pricing-card'; // Unique slug
public $icon = 'ti-layout-grid3-alt'; // Themify Icons class
public $css_selector = '.pricing-card'; // Root selector for CSS rules
public $scripts = [ 'bricksPricingCard' ]; // frontend JS callbacks (optional)
public function get_label() {
return esc_html__( 'Pricing Card', 'my-theme' );
}
public function set_control_groups() {
$this->control_groups['plan'] = [
'title' => esc_html__( 'Plan', 'my-theme' ),
'tab' => 'content',
];
}
public function set_controls() {
$this->controls['planName'] = [
'group' => 'plan',
'label' => esc_html__( 'Plan name', 'my-theme' ),
'type' => 'text',
'default' => 'Pro',
];
$this->controls['price'] = [
'group' => 'plan',
'label' => esc_html__( 'Price', 'my-theme' ),
'type' => 'text',
'default' => '$29/mo',
];
}
public function render() {
$name = isset( $this->settings['planName'] ) ? $this->settings['planName']: '';
$price = isset( $this->settings['price'] ) ? $this->settings['price']: '';
$this->set_attribute( '_root', 'class', 'pricing-card' );
$root = $this->render_attributes( '_root' );
echo "<div {$root}>";
echo '<h3>' . esc_html( $name ) . '</h3>';
echo '<p class="price">' . esc_html( $price ) . '</p>';
echo '</div>';
}
}
Save as your-theme/bricks/elements/pricing-card.php.
Hook into bricks/load_elements/after: fires in includes/elements.php:302 after Bricks has loaded its own elements.
add_action( 'bricks/load_elements/after', function() {
require_once get_stylesheet_directory() . '/bricks/elements/pricing-card.php';
\Bricks\Elements::register_element(
get_stylesheet_directory() . '/bricks/elements/pricing-card.php',
'pricing-card',
'MyTheme\\Bricks\\Pricing_Card'
);
} );
Elements::register_element() signature (includes/elements.php:255):
$name)If you omit args 2 & 3, Bricks auto-discovers the class via get_declared_classes(): works but is fragile. Explicit registration is better.
The base Element class provides defaults. Override only what the element needs:
| Method | File:line | Purpose |
|---|---|---|
get_label() | base.php | Return the translated element name. The base fallback derives a label from $name. |
set_control_groups() | base.php:372 | Optional. Populate $this->control_groups array when you need custom groups. |
set_controls() | base.php:379 | Populate $this->controls array for element settings. |
render() | base.php:3042 | Frontend HTML output and PHP AJAX builder output for elements without an x-template. |
render_builder() | base.php:3049 | Optional static method. Echoes the builder x-template script when you want a Vue-rendered preview. |
Most elements override only get_label() + set_controls() + render(). set_control_groups() only if you want tabs beyond the default content / style.
| Property | Type | Purpose |
|---|---|---|
$category | string | 'general' / 'layout' / 'media' / 'seo' / 'woocommerce' / custom: element panel group |
$name | string | Unique slug (hyphen-case). Must match register_element's arg 2. |
$icon | string | Themify Icons class (default icon set in Bricks) |
$css_selector | string | Selector used by Bricks' CSS generator to scope controls: usually the element's root class |
$scripts | array | Names of JS callbacks Bricks should call on frontend init |
$nestable | bool | Whether this element accepts arbitrary children. Default false (base.php:68) |
$tag | string | Default HTML tag for the root wrapper ('div' typically) |
$controls | array | Populated by set_controls() |
$settings | array | Resolved settings for the current instance (populated by Bricks at render time) |
$is_frontend | bool | True on frontend, false in builder context (base.php:48, 90) |
Your render() method runs on the frontend. In the builder, Bricks chooses one of two render paths:
tmpl-bricks-element-{name} exists, the iframe uses the Vue x-template (src/vue/store/actions.js:4274).bricks-element-php, which renders through PHP AJAX (src/vue/store/actions.js:4279, src/vue/iframe.js:79).Two options:
Omit render_builder(). Bricks will not print an x-template for the element, so the builder falls back to the PHP render path.
Tradeoff: slower builder (round-trip per edit), but guaranteed visual parity.
Override static render_builder() and echo a script template that reproduces your PHP render logic client-side. Builder::element_x_templates() calls each registered element class's render_builder() in the builder iframe (includes/builder.php:1202-1208).
<script type="text/x-template" id="tmpl-bricks-element-pricing-card">
<div class="pricing-card">
<h3>{{ settings.planName }}</h3>
<p class="price">{{ settings.price }}</p>
</div>
</script>
Tradeoff: faster builder, but you maintain two render paths.
Rule of thumb: if your element has heavy PHP logic (queries, complex formatting), use Option 1. If it's mostly presentation, use Option 2.
To support {post_title} inside your element's text control:
$name = $this->render_dynamic_data( $this->settings['planName'] );
This runs the value through Bricks' dynamic-data pipeline. Without it, {post_title} renders literally.
render_attributes()Bricks generates classes, id, custom attributes from the element's panel (ID/Class control, custom attributes control). Emit via:
$root_attrs = $this->render_attributes( '_root' );
echo "<div {$root_attrs}>...</div>";
_root is the default selector key. For non-root wrappers, define additional selectors in your controls with a css key and call render_attributes('my-custom-selector').
Use the element's enqueue_scripts() method for its assets and declare a named
initializer in $scripts for Bricks' render/update lifecycle. The initializer must
handle repeated calls and newly inserted nodes without duplicating listeners.
function examplePricingCard() {
bricksQuerySelectorAll(document, '.pricing-card').forEach((element) => {
if (element.dataset.examplePricingCardReady) return
element.dataset.examplePricingCardReady = 'true'
// Attach the element's actual event handlers here.
})
}
bricksQuerySelectorAll takes (parentNode, selector). Register
public $scripts = [ 'examplePricingCard' ]; and enqueue the file with the
bricks-scripts dependency. For stateful widgets, update existing instances or
clean them up before rebuilding when settings change; a ready marker alone is
sufficient only for initialization that remains valid for the existing node.
See the bricks-custom-controls skill for the complete list. The big ones: text, textarea, number, select, checkbox, color, typography, background, border, box-shadow, spacing, dimensions, icon, image, repeater, code, query, query-list, link.
requiredShow one control only when another has a specific value:
'highlightColor' => [
'label' => 'Highlight color',
'type' => 'color',
'required' => [ 'highlight', '=', true ], // only when `highlight` control is true
],
'cardPadding' => [
'label' => 'Padding',
'type' => 'dimensions',
'css' => [
[
'property' => 'padding',
'selector' => '', // empty = apply to the css_selector root
],
],
'default' => [ 'top' => '20px', 'right' => '20px', 'bottom' => '20px', 'left' => '20px' ],
],
Bricks generates CSS from css entries automatically: no need to emit style in render().
Set $this->nestable = true; in the constructor (pre-1.9) or as a class property (1.9+). Then override get_nestable_item() to return the default child template.
See bricks-nestable-elements skill for the full contract.
Element doesn't appear in builder panel?
a. register_element() not called. Check the hook firing.
b. Class namespace wrong. Fully-qualified name required.
c. File not loaded: require_once path wrong.
Element shows in builder but blank?
a. render() missing or empty.
b. render() calling undefined methods / throwing. Check wp-content/debug.log.
Dynamic tags render literally ({post_title} as text)?
a. Missing render_dynamic_data( $value ) wrap.
Controls show but changes don't persist?
a. Control name mismatch: the key in set_controls() must match what you read in render() via $this->settings[key].
Builder preview looks broken; frontend fine?
a. The x-template returned by render_builder() does not match render(), or the PHP fallback throws during the builder AJAX render.
CSS from css controls not applying?
a. Selector in css entry doesn't match what render() emits. Bricks scopes to .brxe-{name} by default: verify the root class.
WP_DEBUG + WP_DEBUG_LOG on.get-page-elements includes your element in the tree, and get-element-schema returns its controls when the element is registered.<script> tags inside render(). Use proper enqueue via wp_enqueue_script.esc_html/esc_attr on user-provided settings values. Bricks' settings pipeline sanitizes at save time but values can drift.__() / esc_html__(). Bricks is multi-lingual.get_header, get_footer) inside render(): you're inside the page already.bricks/load_elements/after is the right moment.$this->settings directly in render(): it's populated by Bricks; treat as read-only.render_attributes('_root') when emitting the root element. You lose the ID/Class panel bindings.bricks-custom-controls: control type reference and patterns.bricks-custom-code: where element PHP fits among the 7 extension points.bricks-hooks-reference: hooks like bricks/element/render_attributes for post-render tweaks.bricks-child-theme-patterns: where to put element files in a child theme.What SKILL.md sets; muted values are Claude Code's defaults
/bricks:bricks-custom-elementsfrom bricks
npx claudepluginhub codeerhq/bricks-skills --plugin bricks46 skills in this plugin
/bricks-agent-repositoryHandle complex existing-site Bricks edits through advertised repository/workspace workflows when focused abilities cannot express the change./bricks-ai-tabDiagnose Bricks AI connection setup, ability toggles, dispatcher availability and disabled actions. Use for connection/availability problems./bricks-audit-design-systemAudit Bricks classes, variables, palettes and components, or carry out requested cleanup. Report-only audits do not authorize fixes.Other plugins' skills for the same job