Created
September 25, 2013 01:25
-
-
Save jlittlejohn/6693874 to your computer and use it in GitHub Desktop.
WP: Setting & Getting Cookies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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