Ryan Sherman
Ryan Sherman

Reputation: 57

Not returning proper output when cookie is set in WordPress

I am trying to setup an age verification box for a website in WordPress. I am using jQuery Cookie to set the cookie when the button is clicked. jQuery hides the box once it is clicked and then if the cookie is already set it shouldn't display the age verification box on subsequent pages. I tested this on another site which works without issue but on the current site it only works when logged in as an admin. Normal users see the box on every page, even though I have verified in Firebug that the cookie is set. Any ideas?

Here is how I am checking for the cookie on the page:

<?php if( !isset( $_COOKIE['consenting_age'] ) ) { ?>

    <div>Age Verification Box Here</div>

<?php } ?>

Here is a link to the site in question http://cutlersartisan.wpengine.com/distilery/

Upvotes: 1

Views: 860

Answers (1)

Martin
Martin

Reputation: 2427

The problem is related to the caching that wpengine has implemented see Cookies and PHP Sessions and not the following

Looking at your site the problem is not in the php code but where you set the cookie value

    $j.cookie('consenting_age', 'yes', { expires: 30, path: '/', domain: '.cutlersartisan.wpengine.com' });

your domain name has a . at the front

try

    $j.cookie('consenting_age', 'yes', { expires: 30, path: '/', domain: 'cutlersartisan.wpengine.com' });

or leave out the domain completely

    $j.cookie('consenting_age', 'yes', { expires: 30, path: '/'});

Upvotes: 3

Related Questions