The Conditions

The Cookie Condition

In this article: About the cookie condition| Types of cookie-based content | How to set up cookie-based content using If-So

The cookie condition allows you to display dynamic content to users visiting your site based on a cookie name, cookie value, or both.

This option was created to allow site admins and developers to create dynamic content based on cookies that are already in use by the website, whether they are created by a 3rd-party plugin or using a custom code. It can be used to interact with users based on previous interactions they have had with your site and allows you to give your visitors a more personalized experience.

Display dynamic content based on the cookie name, value, or both

With If-So you can easily display dynamic content based on a cookie name, a cookie value, or both. 

Cookie Name:  Fill in the cookie name field and leave the cookie value field blank. The dynamic content will be displayed if a cookie with the exact name exists in the user’s browser, regardless of its value.

Cookie Value:  Fill in the cookie value field and leave the name field blank. The dynamic content will be displayed if a cookie with the exact value exists in the user’s browser, regardless of its name

Cookie Name and Cookie Value:  Fill in both the cookie name and the cookie value. The dynamic version will be displayed only if the cookie in the user’s browser matches both the name and value you have set.

*Elementor or Gutenberg user? This condition can be used to set up a conditional element or block (Learn more: Gutenberg | Elementor).

  1. On your WordPress dashboard, go to “If-So → Add New Trigger”
  2. Click on “Select a condition” and select “Cookie“.
  3. Type in the Cookie Name and/or Cookie Value
  4. In the content field, set the content to be displayed if the cookie condition you have set is met.
  5. In the default content field, set content to be displayed if the condition is not met (optional, can be left blank).
  6. Press “Publish” and paste the shortcode generated by If-So wherever you want it to go.

Add or remove cookies shortcodes

If-So allows you to add, remove, or change a value of a cookie when users click a certain element or visit a certain page.

To add or remove a cookie when the user visits a page, simply paste the following shortcodes on the relevant page:

Adding a cookie

[ifso-add-cookie name='COOKIE_NAME' value='COOKIE_VALUE' time='3600']
  • Make sure to replace ‘COOKIE_NAME’ and ‘COOKIE_VALUE’ with a name and value of your choice.
  • The time parameter controls the cookie expiration time (in seconds, 3600 sec = 1 hour; 86400 = 1 day).

Removing a cookie using a shortcode

[ifso-remove-cookie name='COOKIE_NAME']

Replacing the value of an existing cookie

A cookie value will be replaced if a shortcode with a different cookie value is rendered.

Learn more about assigning a cookie using a shortcode.

Add a cookie when the user clicks an element

Assigning a cookie upon element click is an extra functionality added by our Trigger Events extension (download).

Adding a cookie on click is done using a wrapping shortcode. You can choose if you only want to add a cookie when users click the element, or if you also want to redirect them to a different page in addition.

[ifso_onclick_redirect  clicks='1' cookie_name='hello' cookie_value='awesome' expires='3600' ]Click here to add a cookie[/ifso_onclick_redirect]

Shortcode parameters:

clicks: The number of times the element should be clicked

cookie_name: The name of the cookie that will be created

cookie_value: The value of the cookie that will be created

expires: The cookie expiration in minutes

URL: Add a URL parameter to the shortcode to redirect users to a different page after clicking the element (in addition to adding the cookie).

[ifso_onclick_redirect  url='https://example.com' clicks='3' cookie_name='hello' cookie_value='world' expires='3600' ]Click here 3 times to see the result[/ifso_onclick_redirect]

Can I display dynamic content based on a browser session?

Yes. The same logic described for the cookie condition applies if you want to display content based on a browser session (Simply select “Session” instead of “Cookie” when you set up the condition).

Screenshots

FAQs

  • Will this work with server and WordPress caching solutions?

    Yes.

    Whether you are using a caching plugin or server caching, you can navigate to the plugin settings and enable the "Page Caching Compatibility" option. With the option enabled, dynamic triggers will be rendered in a separate request that will take place after the loading of the cached version.

    Learn more about Page Caching Compatibility.

  • Can I redirect users to a different page based on conditions?
    Yes. You can redirect users based on each one of the conditions by pasting a simple JavaScript code in the dynamic version content field. Click here for a step by step guide.
  • Was this Helpful ?
  • YesNo
Ready to get started?
Try it on your website