How to Display Blocks Based on Cookies?
๐ Note: This is part of the Otter PRO features library, which you can get from here.
Enabling the Panel |
Using the Condition |
Example |
๐ฒ Enabling the Panel
Blocks visibility can be controlled using the Visibility Conditions that Otter brings in. These can be found under Block Tools, and clicking on them to create a separate panel.
After enabling the panel, open it to insert conditions. This article will present an example of Cookie-based visibility conditions:
This condition is based on the PHP cookies. These cookies are small fragments of data stored on a client browser, which makes the user recognizable.
๐งฐ Using the Condition
Using this condition, the website will recognize the user using the cookies and display / not display the blocks anymore.
- 1
-
First, pick the Cookie condition from the dropdown.
- 2
-
Insert the cookie's key in the field. This is equal to the cookie's name.
- 3
-
Pick the compare operator. It can be is True/False/Empty or if Equals/Contains.
๐ Note: Based on the operator, other fields may appear.
- 4
-
Select the block's behavior if the condition is met (Visible/Hidden).
๐กExample
In the example below, we have created a cookie named user and inserted it in otter-blocks.php, then we have added the key inside the field.
๐กResult