I created a cookie in PHP:
function set_newuser_cookie() {
if ( !is_admin() && !isset($_COOKIE['sitename_newvisitor'])) {
setcookie( 'sitename_newvisitor', 1, time()+3600*24*365, COOKIEPATH, COOKIE_DOMAIN, false);
}
}
add_action( 'init', 'set_newuser_cookie');
I want to delete this cookie in a javascript file after a click event, like so:
$('.tbf-main-logo-image').on('click', function() {
document.cookie = 'sitename_newvisitor=;expires=Thu, 01-Jan-70 00:00:01 GMT;';
});
I have been on every stack overflow thread pertaining to this issue and I have tried: adding a path to the cookie, made a delete_cookie
function, using jQuery $.removeCookie
. Nothing seems to be working. One thought is that perhaps everytime my header is loading it is recreating the cookie? But no, it shouldn't because I have an if statement looking for a cookie with that name. Help!