I'm trying to set a custom cookie in Wordpress. This code is in my theme's functions.php. I'm getting all of the echos, but it will not create the cookie and I'm stumped. This should have taken 5 minutes and I cannot figure out why it HATES me!
It's using the 'init' hook and therefore should be processed BEFORE the headers are sent!
add_action( 'init', 'checking_my_cookie' );
function setting_my_first_cookie() {
setcookie( 'unicorn', 'cupcakes', 30 * DAY_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN, true, false);
}
function checking_my_cookie(){
if(!isset($_COOKIE['unicorn'])) {
setting_my_first_cookie();
} else {
}
}