Skip to content

Instantly share code, notes, and snippets.

@micc83
Created September 5, 2013 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micc83/6451181 to your computer and use it in GitHub Desktop.
Save micc83/6451181 to your computer and use it in GitHub Desktop.
Set cookie in wp
<?php
function set_newuser_cookie() {
if (!isset($_COOKIE['sitename_newvisitor'])) {
setcookie('sitename_newvisitor', 1, time() + HOUR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN, false);
}
}
add_action( 'init', 'set_newuser_cookie');
/**
* MINUTE_IN_SECONDS = 60 (seconds)
* HOUR_IN_SECONDS = 60 * MINUTE_IN_SECONDS
* DAY_IN_SECONDS = 24 * HOUR_IN_SECONDS
* WEEK_IN_SECONDS = 7 * DAY_IN_SECONDS
* YEAR_IN_SECONDS = 365 * DAY_IN_SECONDS
*
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment