bricks_set_element_conditions

Phase 4AdvancedComplexity: 7/10
Set visibility conditions on elements (60+ condition types)

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

Server-Side Evaluation
Conditions are evaluated on the server before HTML is sent to the browser. Hidden elements are completely removed from the output — they do not appear in the page source or DOM.
Five Condition Groups
Supports post conditions (type, status, ID, taxonomy), user conditions (role, login status, capability), date conditions (day, time, range), WooCommerce conditions (cart, product), and other conditions (dynamic data, URL parameters).
AND/OR Logic
Combine multiple conditions with AND (all must match) or OR (any must match) logical operators for complex visibility rules.
Show or Hide Action
Choose whether matching conditions cause the element to be shown (display only when conditions match) or hidden (remove when conditions match).

When to Use

Show content only to logged-in users or specific user roles
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
Prerequisites
Page and element must already exist
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 user-triggered show/hide (click, hover) — use bricks_add_interaction instead
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

11 Total Parameters5 Required6 Optional
page_idnumberREQUIRED
The WordPress page (post) ID containing the element.
element_idstringREQUIRED
The Bricks element ID to set conditions on.
conditionsarrayREQUIRED
Array of condition objects defining the visibility rules.
conditions[].mainstringREQUIRED
The condition group category.
Values: post, user, date, woocommerce, other
conditions[].keystringREQUIRED
The specific condition key within the group (e.g., "post_type", "user_role", "date_weekday", "dynamic_data").
conditions[].comparestringoptional
Comparison operator for the condition.
Default: == Values: ==, !=, >, <, >=, <=, contains, contains_not, empty, empty_not
conditions[].valuestring|number|arrayoptional
Value to compare against. Can be a string, number, or array (for multi-select conditions like user_role).
conditions[].dynamic_datastringoptional
Dynamic data tag for the "dynamic_data" condition key (e.g., "{acf_is_premium}").
actionstringoptional
Whether to hide or show the element when conditions match.
Default: hide Values: show, hide
logicalOperatorstringoptional
Logic between multiple conditions.
Default: AND Values: AND, OR
content_areastringoptional
Content area where the element resides.
Default: content Values: content, header, footer

Code 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.

JSON
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.

JSON
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
Conditions are server-side and data-driven (evaluated before render). Interactions are client-side and event-driven (triggered by user actions). Use conditions for "who can see this" and interactions for "what happens when they click".

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
To hide elements on mobile, use _display:mobile_portrait: "none" via responsive settings, not visibility conditions. Conditions evaluate WordPress data, not screen size.

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
The action parameter defines what happens when conditions MATCH. action: "hide" means hide the element when conditions are true. action: "show" means show the element only when conditions are true.

Tips & Warnings

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

Return Values

FieldTypeDescription
successbooleanWhether the conditions were successfully set on the element.
messagestringConfirmation with the element ID, action type, number of conditions, and logical operator.
conditionsarrayThe conditions array as stored on the element, including any auto-generated IDs.

Related Tools

Technical Details

Tool ID
bricks_set_element_conditions
API Endpoint
/bricks-mcp/v1/pages/{page_id}/elements/{element_id}/conditions
HTTP Method
PUT
Namespace
pages-elements
Source File
pages/interactions.ts
Version
1.0
Min Bricks Version
1.9
Requires Auth
Yes

Changelog

v1.0
Initial release with five condition groups, AND/OR logic, show/hide actions, and dynamic data support.
20250101