Data Attribute-based Conditional Output in Bricks

In the Bricks Facebook group a user asks:

Data Attribute as a Condition

Is it possible to place a data attribute as an element condition, if yes, how?

Before Bricks added the ability to set conditions on elements in the editor, we'd use bricks/element/render filter for the conditional output.

This Pro tutorial shows how this filter can be used to not render elements that have a specific data attribute with a name of data-dont-output set.

On the front end:

Add the following in child theme's functions.php (w/o the opening PHP tag) or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 537 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Conditionally Outputting Query Loop Item Based on Post Meta in Bricks

Conditionally Outputting Query Loop Item Based on Post Meta in Bricks

Rendering query-loop enabled posts depending on the value of each post's custom field value is tricky because by default, the custom field plugins' functions or…
Categories:
Pro
Dynamic Date in Bricks Countdown Element

Dynamic Date in Bricks Countdown Element

As of Bricks 1.9.7.1, the built-in Countdown element's Date control does not support dynamic data. That is, it is not possible to set this date…
Pro
Restrict Content Pro in Bricks

Restrict Content Pro in Bricks

This Pro tutorial provides the steps to restrict Pages and individual elements like Sections in Bricks depending on whether the current user has any active…
Pro
Conditional Rendering in Bricks Based on CSS Class

Conditional Rendering in Bricks Based on CSS Class

Updated on 19 Jun 2024 A user asks: Is there a way to apply the same conditions to several elements like we set styles appending…
Categories:
Pro
Conditional Rendering Based On Meta Box Group’s Sub Field

Conditional Rendering Based On Meta Box Group’s Sub Field

This Pro tutorial shows how we can output an element on a single post pages only if a specified sub-field (custom field created using Meta…