bricks_set_element_conditions
Overview
Sets visibility conditions on a Bricks element, controlling whether it is shown or hidden based on dynamic WordPress data. Conditions evaluate server-side data such as post type, user role, date, WooCommerce state, and custom field values to determine element visibility at render time.
This is fundamentally different from interactions: conditions are evaluated on the server before the page is rendered, while interactions are client-side JavaScript behaviors. Use conditions for data-driven visibility (show pricing only to logged-in users, hide CTA on archive pages) and interactions for user-triggered behaviors (show on click, animate on scroll).
Key Features
When to Use
Hide elements on specific post types or page templates
Display seasonal content based on date ranges
Show WooCommerce-specific content only when cart has items
Conditionally display content based on ACF or custom field values
Create A/B test variants using dynamic data conditions
Element ID must be known (use bricks_get_page_content)
For ACF/custom field conditions, the fields must be configured in WordPress
When NOT to Use
For responsive visibility (hide on mobile) — use _display:mobile_portrait: "none" via bricks_set_responsive_settings
For styling changes based on state — use CSS classes and interactions
Parameters
page_idnumberREQUIREDelement_idstringREQUIREDconditionsarrayREQUIREDconditions[].mainstringREQUIREDpost, user, date, woocommerce, otherconditions[].keystringREQUIREDconditions[].comparestringoptional== Values: ==, !=, >, <, >=, <=, contains, contains_not, empty, empty_notconditions[].valuestring|number|arrayoptionalconditions[].dynamic_datastringoptionalactionstringoptionalhide Values: show, hidelogicalOperatorstringoptionalAND Values: AND, ORcontent_areastringoptionalcontent Values: content, header, footerCode Examples
Warning: Undefined array key "example_output" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 12
Show premium content only to logged-in users
Set a condition that shows a pricing section only when the visitor is logged in with the subscriber or administrator role.
bricks_set_element_conditions({
page_id: 42,
element_id: "abc123",
conditions: [
{
main: "user",
key: "user_role",
compare: "==",
value: ["subscriber", "administrator"]
}
],
action: "show",
logicalOperator: "AND"
})Warning: Undefined array key "example_output" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 12
Hide promotional banner based on ACF field
Hide a promotional banner element when the ACF field "hide_promo" is set to true on the current post.
bricks_set_element_conditions({
page_id: 42,
element_id: "promo1",
conditions: [
{
main: "other",
key: "dynamic_data",
compare: "==",
value: "1",
dynamic_data: "{acf_hide_promo}"
}
],
action: "hide"
})Common Mistakes
Warning: Undefined array key "fix_description" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 47
Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-includes/kses.php on line 2018
Warning: Undefined array key "wrong_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 48
Warning: Undefined array key "right_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 49
Warning: Undefined array key "fix_description" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 47
Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-includes/kses.php on line 2018
Warning: Undefined array key "wrong_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 48
Warning: Undefined array key "right_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 49
Warning: Undefined array key "fix_description" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 47
Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-includes/kses.php on line 2018
Warning: Undefined array key "wrong_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 48
Warning: Undefined array key "right_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 49
Tips & Warnings
Server-side removal: When conditions evaluate to « hide, » the element is completely removed from the rendered HTML. It does not exist in the DOM at all, which is more secure than client-side hiding for sensitive content.
Condition groups: Common keys by group:
– post: post_type, post_status, post_id, post_parent, taxonomy terms
– user: user_role, user_logged_in, user_id, user_capability
– date: date_weekday, date_time, date_range
– woocommerce: cart_empty, product_in_cart, product_type
– other: dynamic_data, url_parameter, browser, referrer