I am trying to set a cookie, based on a GET variable from a page.
The page URL looks like: mysite.com/?my_var=somevalue
I'm trying this, but can't see what I'm doing wrong..
// make 'my_var' available as get_query_var('my_var')..
function add_query_vars_filter($vars){
$vars[] = "my_var";
return $vars;
}
add_filter('query_vars', 'add_query_vars_filter');
add_action('init', 'my_setcookie');
// take the query_var 'my_var' and set it as cookie 'my_cookie'
function my_setcookie() {
setcookie('my_cookie', get_query_var('my_var'), strtotime('+1 day'));
}
Would love a little help with this!
Thanks in advance.
my_var
or on specific page like homepage or post page. :)