| name | bricks-hooks |
| description | Use filters and actions available in Bricks Builder for customization. |
Bricks Hooks Skill
This skill covers all filters and actions available in Bricks Builder for customization.
Filter Reference
Element Filters
add_filter( 'bricks/elements/{element_name}/controls', function( $controls ) {
$controls['myNewControl'] = [
'tab' => 'content',
'label' => 'My Control',
'type' => 'text',
];
return $controls;
}, 10, 1 );
add_filter( 'bricks/elements/{element_name}/control_groups', function( $groups ) {
$groups['myGroup'] = [
'title' => 'My Group',
'tab' => 'content',
];
return $groups;
}, 10, 1 );
add_filter( 'bricks/elements/{element_name}/scripts', function( $scripts ) {
$scripts[] = 'myCustomScript';
return $scripts;
}, 10, 1 );
add_filter( 'bricks/builder/elements', function( $element_names ) {
$element_names[] = 'my-custom-element';
$key = array_search( 'testimonials', $element_names );
if ( $key !== false ) {
unset( $element_names[ $key ] );
}
return $element_names;
}, 10, 1 );
add_filter( 'bricks/frontend/render_element', function( $html, $element_instance ) {
if ( $element_instance->name === 'button' ) {
$html = '<div class="button-wrapper">' . $html . '</div>';
}
return $html;
}, 10, 2 );
add_filter( 'bricks/element/render_attributes', function( $attributes, $key, $element ) {
if ( $key === '_root' && $element->name === 'image' ) {
$attributes['class'][] = 'my-image-class';
}
return $attributes;
}, 10, 3 );
Frontend Rendering Filters
add_filter( 'bricks/frontend/render_data', function( $content, $post, $area ) {
return $content;
}, 10, 3 );
add_filter( 'bricks/frontend/disable_seo', function( $disable ) {
return true;
}, 10, 1 );
add_filter( 'bricks/frontend/disable_opengraph', function( $disable ) {
return true;
}, 10, 1 );
add_filter( 'bricks/header/attributes', function( $attributes ) {
$attributes['data-custom'] = 'value';
return $attributes;
}, 10, 1 );
add_filter( 'bricks/content/attributes', function( $attributes ) {
return $attributes;
}, 10, 1 );
( , function( ) {
;
}, , );
( , function( , , , ) {
;
}, , );
( , function( , , , ) {
;
}, , );
( , function( ) {
;
}, , );
( , function( ) {
;
}, , );
( , function( , , ) {
;
}, , );
Query Filters
add_filter( 'bricks/posts/query_vars', function( $query_vars, $settings, $element_id ) {
$query_vars['posts_per_page'] = 12;
return $query_vars;
}, 10, 3 );
add_filter( 'bricks/terms/query_vars', function( $query_vars, $settings, $element_id ) {
$query_vars['hide_empty'] = false;
return $query_vars;
}, 10, 3 );
add_filter( 'bricks/users/query_vars', function( $query_vars, $settings, $element_id ) {
return $query_vars;
}, 10, 3 );
Dynamic Data Filters
add_filter( 'bricks/dynamic_data/register_providers', function( $providers ) {
$providers[] = 'my_custom_provider';
return $providers;
}, 10, 1 );
Template Filters
add_filter( 'bricks/api/get_templates_data', function( $templates_data ) {
return $templates_data;
}, 10, 1 );
add_filter( 'bricks/get_templates', function( $templates, $args ) {
return $templates;
}, 10, 2 );
Theme Styles Filters
add_filter( 'bricks/theme_styles', function( $styles ) {
return $styles;
}, 10, 1 );
add_filter( 'bricks/theme_styles/controls', function( $controls ) {
return $controls;
}, 10, 1 );
add_filter( 'bricks/theme_styles/control_groups', function( $groups ) {
return $groups;
}, 10, 1 );
add_filter( 'bricks/theme_style_name', function( $name, $theme_style ) {
return $name;
}, 10, 2 );
Setup & Options Filters
add_filter( 'bricks/setup/control_options', function( $options ) {
$options['buttonSizes']['xl'] = 'Extra Large';
$options['styles']['brand'] = 'Brand';
return $options;
}, 10, 1 );
add_filter( 'bricks/builder/image_size_options', function( $sizes ) {
return $sizes;
}, 10, 1 );
add_filter( 'bricks/builder/map_styles', function( $styles ) {
$styles['my-style'] = [
'label' => 'My Custom Style',
'value' => '[{"featureType":"all",...}]',
];
return $styles;
}, 10, 1 );
add_filter( 'bricks/body/attributes', function( $attributes ) {
$attributes['data-theme'] = 'dark';
return ;
}, , );
Condition Filters
add_filter( 'bricks/conditions/groups', function( $groups ) {
$groups[] = [
'name' => 'my_conditions',
'label' => 'My Conditions',
];
return $groups;
}, 10, 1 );
add_filter( 'bricks/conditions/options', function( $options ) {
$options[] = [
'key' => 'my_condition',
'group' => 'my_conditions',
'label' => 'My Custom Condition',
'compare' => [
'type' => 'select',
'options' => [
'==' => 'is',
'!=' => 'is not',
],
],
'value' => [
'type' => 'text',
],
];
return $options;
}, 10, 1 );
add_filter( 'bricks/conditions/result', function( $result, $condition, $post_id ) {
if ( $condition[] === ) {
= ( , , );
= [] ?? ;
= [] ?? ;
( === ) {
= === ;
} {
= !== ;
}
}
;
}, , );
Popup Filters
add_filter( 'bricks/popup/attributes', function( $attributes, $popup_id ) {
$attributes['data-popup'] = $popup_id;
return $attributes;
}, 10, 2 );
Link CSS Selectors
add_filter( 'bricks/link_css_selectors', function( $selectors ) {
$selectors[] = '.my-custom-link';
return $selectors;
}, 10, 1 );
Assets Filters
add_filter( 'bricks/assets/generate_css_from_element', function( $css_array, $element, $css_type ) {
return $css_array;
}, 10, 3 );
Auth Redirects Filters
add_filter( 'bricks/auth/custom_redirect_url', function( $url, $current_path ) {
return $url;
}, 10, 2 );
add_filter( 'bricks/auth/custom_login_redirect', function( $page_id ) {
return $page_id;
}, 10, 1 );
add_filter( 'bricks/auth/custom_registration_redirect', function( $page_id ) {
return $page_id;
}, 10, 1 );
add_filter( 'bricks/auth/custom_lost_password_redirect', function( $page_id ) {
return $page_id;
}, 10, 1 );
Pagination Filters
add_filter( 'bricks/pagination/custom_logic', function( $result, $query_settings, $element ) {
return $result;
}, 10, 3 );
add_filter( 'bricks/pagination/current_page', function( $page, $query_settings, $element ) {
return $page;
}, 10, 3 );
add_filter( 'bricks/pagination/total_pages', function( $pages, $query_settings, $element ) {
return $pages;
}, 10, 3 );
Query Filters (Advanced)
add_filter( 'bricks/query_filters/index_args', function( $args, $source, $settings, $type ) {
return $args;
}, 10, 4 );
add_filter( 'bricks/query_filters_indexer/post/{filter_source}', function( $rows, $post, $filter_id, $settings ) {
return $rows;
}, 10, 4 );
Password Protection Filters
add_filter( 'bricks/password_protection/is_active', function( $active, $template_id, $settings ) {
return $active;
}, 10, 3 );
add_filter( 'bricks/password_protection/cookie_expires', function( $expires ) {
return time() + 30 * DAY_IN_SECONDS;
}, 10, 1 );
SVG Filters
add_filter( 'bricks/svg/bypass_sanitization', function( $bypass, $file ) {
if ( strpos( $file, 'trusted-path' ) !== false ) {
return true;
}
return $bypass;
}, 10, 2 );
Custom Fonts Filters
add_filter( 'bricks/custom_fonts/mime_types', function( $types ) {
$types['woff2'] = 'font/woff2';
return $types;
}, 10, 1 );
AJAX Filters
add_filter( 'bricks/ajax/get_pages_args', function( $args ) {
return $args;
}, 10, 1 );
add_filter( 'bricks/builder/post_title', function( $title, $post_id ) {
return $title;
}, 10, 2 );
add_filter( 'bricks/builder/term_name', function( $name, $term_id, $taxonomy ) {
return $name;
}, 10, 3 );
Code Execution Filter
add_filter( 'bricks/code/disable_execution', function( $disable ) {
return true;
}, 10, 1 );
WooCommerce Filters
add_filter( 'bricks/woocommerce/products_filters/options', function( $options, $settings ) {
return $options;
}, 10, 2 );
Action Reference
Frontend Rendering Actions
add_action( 'bricks/frontend/before_render_data', function( $elements, $area ) {
}, 10, 2 );
add_action( 'bricks/frontend/after_render_data', function( $elements, $area ) {
}, 10, 2 );
Query Actions
add_action( 'bricks/query/before_loop', function( $query_obj, $args ) {
}, 10, 2 );
add_action( 'bricks/query/after_loop', function( $query_obj, $args ) {
}, 10, 2 );
add_action( 'bricks/query/query_api_response', function( $response, $element_id ) {
}, 10, 2 );
Dynamic Data Actions
add_action( 'bricks/dynamic_data/tags_registered', function() {
}, 10, 0 );
add_action( 'bricks/dynamic_data/before_do_action', function( $action, $filters, $context, $post ) {
}, 10, 4 );
add_action( 'bricks/dynamic_data/after_do_action', function( $action, $filters, $context, $post, $value ) {
}, 10, 5 );
Form Actions
add_action( 'bricks/form/custom_action', function( $form ) {
}, 10, 1 );
add_action( 'bricks/form/action/{action_name}', function( $form ) {
}, 10, 1 );
Query Filters Actions
add_action( 'bricks/query_filters/index_post/before', function( $post_id ) {
}, 10, 1 );
add_action( 'bricks/query_filters/index_user/before', function( $user_id ) {
}, 10, 1 );
Filter Element Actions
add_action( 'bricks/filter_element/before_set_data_source_from_custom_field', function( $element ) {
}, 10, 1 );
CSS File Generation Actions
add_action( 'bricks/generate_css_file', function( $type, $file_name ) {
}, 10, 2 );
API Actions
add_action( 'bricks/render_query_page/start', function( $request_data ) {
}, 10, 1 );
add_action( 'bricks/render_popup_content/start', function( $request_data ) {
}, 10, 1 );
add_action( 'bricks/render_query_result/start', function( $request_data ) {
}, 10, 1 );
Common Use Cases
Adding Custom Element Controls
add_filter( 'bricks/elements/posts/controls', function( $controls ) {
$controls['readMoreText'] = [
'tab' => 'content',
'group' => 'content',
'label' => esc_html__( 'Read More Text', 'bricks' ),
'type' => 'text',
'default' => 'Read More',
'placeholder' => 'Read More',
];
return $controls;
} );
Custom Condition for Templates
add_filter( 'bricks/conditions/options', function( $options ) {
$options[] = [
'key' => 'is_weekend',
'group' => 'date',
'label' => esc_html__( 'Is Weekend', 'bricks' ),
'compare' => [
'type' => 'select',
'options' => [
'==' => esc_html__( 'Yes', 'bricks' ),
'!=' => esc_html__( 'No', 'bricks' ),
],
],
];
return $options;
} );
add_filter( 'bricks/conditions/result', function( $result, $condition, $post_id ) {
if ( $condition['key'] === 'is_weekend' ) {
$is_weekend = in_array( date( 'N' ), [ 6, 7 ] );
$compare = $condition['compare'] ?? '==';
$result = $compare === ? : ! ;
}
;
}, , );
Adding Custom Button Style
add_filter( 'bricks/setup/control_options', function( $options ) {
$options['styles']['gradient'] = esc_html__( 'Gradient', 'bricks' );
return $options;
} );
Custom Form Handler
add_action( 'bricks/form/custom_action', function( $form ) {
$fields = $form->get_fields();
$email = '';
foreach ( $fields as $field ) {
if ( $field['id'] === 'email' ) {
$email = $field['value'];
break;
}
}
} );
Modify Posts Query
add_filter( 'bricks/posts/query_vars', function( $vars, $settings, $element_id ) {
$vars['date_query'] = [
[
'after' => '30 days ago',
],
];
return $vars;
}, 10, 3 );
Add Custom CSS Class to All Elements
add_filter( 'bricks/element/render_attributes', function( $attributes, $key, $element ) {
if ( $key === '_root' ) {
$attributes['class'][] = 'bricks-element';
$attributes['class'][] = 'element-' . $element->name;
}
return $attributes;
}, 10, 3 );
Disable Code Element Execution for Non-Admins
add_filter( 'bricks/code/disable_execution', function( $disable ) {
if ( ! current_user_can( 'manage_options' ) ) {
return true;
}
return $disable;
} );
Hook Priority Guide
| Priority | Use Case |
|---|
| 1-9 | Run before most other code |
| 10 | Default priority |
| 11-19 | Run after default |
| 20+ | Run later, useful for overrides |
| 99+ | Run last, final modifications |
Best Practices
- Use specific hooks - Target specific elements rather than global filters when possible
- Check for Bricks - Wrap code in
if ( class_exists( '\Bricks\Elements' ) ) checks
- Cache results - Use transients or static variables for expensive operations
- Early returns - Check conditions early to avoid unnecessary processing
- Clean up - Remove actions/filters when no longer needed
- Document - Comment why each hook is used