Skip to main content
added 117 characters in body
Source Link
ksr89
  • 594
  • 3
  • 13

On the page where you want to set the cookie write this code and check

if(get_query_var('my_var') == 'somevalue'){
    setcookie('my_cookie', get_query_var('my_var'), strtotime('+1 day'));
}

If we go with your code then it will set coookie on every page who having query variable

?my_var=somevalue

On the page where you want to set the cookie write this code and check

if(get_query_var('my_var') == 'somevalue'){
    setcookie('my_cookie', get_query_var('my_var'), strtotime('+1 day'));
}

On the page where you want to set the cookie write this code and check

if(get_query_var('my_var') == 'somevalue'){
    setcookie('my_cookie', get_query_var('my_var'), strtotime('+1 day'));
}

If we go with your code then it will set coookie on every page who having query variable

?my_var=somevalue

Source Link
ksr89
  • 594
  • 3
  • 13

On the page where you want to set the cookie write this code and check

if(get_query_var('my_var') == 'somevalue'){
    setcookie('my_cookie', get_query_var('my_var'), strtotime('+1 day'));
}