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.
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.
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']
Removing a cookie using a shortcode
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.
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]
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]
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).
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.