Toolset Conditional block allows you to display or hide blocks based on conditions you set. The conditional block can include multiple conditions and they can be nested.

The source of the tested data can be a standard or custom field, a Views shortcode that generates output or other custom shortcodes, or a PHP function that returns a value.

The value can be compared against a fixed value (e.g. a number or a string), the value of another custom field, the result of a calculation using fixed values or custom fields, or Views date filters.

Inserting a Conditional block

Let’s start with an example. We have a site about cooking recipes. Each recipe displays information about preparation time, level of difficulty, and more.

We want to show a message to our visitors only if a certain dish can be prepared in under 30 minutes. To do that we add a Conditional block to our page. Next, we add a new block within that Conditional block. In this case, this will be a paragraph block but Conditional block can host any other block, including other conditional blocks.

In the Block Editor, the Conditional block is located in the Toolset group of blocks. You can use multiple Conditional blocks on the same page or a template.

Adding Conditional block
Adding Conditional block

Setting the conditions

After adding the Conditional block, click the Add new conditions button.

Add new conditions
Add new conditions

Use the dialog that appears to select what to compare, the comparison operator, and the value to compare against.

Editing your condition rules
Editing your condition rules

In this dialog, you can also set the condition to be negative, add more conditions, link conditions by AND or OR operators, and group conditions.

Adding content to display conditionally

Next, we need to add content to display when the set conditions are met. To do that, position yourself within the Conditional block and add a new block with your content.

Checking the results

In our example, this is what our visitor will see.

If preparing time is less than 30 minutesIf preparing time is not less than 30 minutes

Advanced Editor mode

Use the Advanced editor switch to set conditions manually using the Views conditional rules. Please note that some conditions might be lost if you switch back to the Visual Editor mode.

Advanced Editor mode
The Conditional block’s Advanced Editor mode