I'm trying to set up, when a specific page/url is visited that a cookie is set and saved.
So far I've tried this:
add_action('init', 'set_cookie', 1);
function set_cookie(){
if ( $currentURL == 'https://25dni.si/delovanje-uma/' ) :
if ( ! isset( $_COOKIE['opt_in'] ) ) :
setcookie( 'opt_in', has_opt_in, time()+31556926);
endif;
endif;
}
Now, when I visit the specific URL, cookie is detected, but when I move on to another page, cookie is gone.
How can the cookie be saved?
I'm pretty new to this, please help me understand.
Thank you!