Hi @seemannslohn,
When a user accepts a cookie, the value of the cookie viewed_cookie_policy will be set “yes” and if rejects the value of the cookie will be “no”. By default, the value of the cookie is “null”. This can be viewed from the developer console when the cookies have been accepted or rejected and the page has been reloaded.
See the screenshot of the value of viewed_cookie_policy, when the cookies are accepted and the cookies have been rejected.
When the value of viewed_cookie_policy is “yes” the corresponding scripts will be rendered. As in the below JS code for Google Analytics, here it will enable for GA if the consent is yes. i.e., the value of the viewed_cookie_policy is “yes”.
<script type="text/javascript"
src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js">
var consent_value = $.cookie("viewed_cookie_policy");
if (consent_value == 'yes')
{
enableGoogleAnalytics(); // enable GA inside this function
}
First: Thanks for your very (!) quick answer.
But I’m sorry, I didn’t get it. Which code do I have to include in my WordPress-PHP-Files?
My idea is to use this syntax:
<?php
if (consent_value == ‘yes’)
{
echo (‘Cookies are accepted’);
{
?>
But the question is: Where and how can I define the var: consent_value, so that I can check it via php if?
Thanx a lot für your patience!
Hi @seemannslohn
You may check that in PHP like below code
(!empty($_COOKIE["viewed_cookie_policy"]) && $_COOKIE["viewed_cookie_policy"] == 'yes'))
Thank you very much. It works:
(!empty($_COOKIE[“viewed_cookie_policy”]) && $_COOKIE[“viewed_cookie_policy”] == ‘yes’)
I am happy! 🙂
One last question: Is there also a [shortcode] I can use in pages?
Hi @seemannslohn,
Please see the shortcode list in the attached screenshot.
Please leave us a review if the plugin/support was helpful.