How can I add a cookie when one specific page has been visited?
I want to redirect new visitors to a questionnaire. When they submit the questionnaire they're redirected to a thank you page. I want the thank you page to place a cookie.
I'd like to know the best way to achieve this with WP. Currently I've got the following in my functions.php, but it doesn't isolate the thank you page:
function set_newuser_cookie() {
if (!isset($_COOKIE['new_visitor'])) {
setcookie('new_visitor', 1, time()+3600*24*100, '/', '.mydomain.com/thank-you/', false);
}
}
add_action( 'init', 'set_newuser_cookie');