Skip to content

Instantly share code, notes, and snippets.

@jlittlejohn
Created September 25, 2013 01:25
Show Gist options
  • Save jlittlejohn/6693874 to your computer and use it in GitHub Desktop.
Save jlittlejohn/6693874 to your computer and use it in GitHub Desktop.
WP: Setting & Getting Cookies
// http://php.net/manual/en/function.setcookie.php
// functions.php
function set_newuser_cookie() {
if (!isset($_COOKIE['sitename_newvisitor'])) {
setcookie('sitename_newvisitor', 1, time()+1209600, '/', 'example.com', false);
}
}
add_action( 'init', 'set_newuser_cookie');
// Theme
if (isset($_COOKIE['sitename_newvisitor'])) {
echo 'Welcome back!';
}
else {
echo 'Hello new visitor!';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment