WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

At first I had my setcookie() as:

$school = "Some Value";
setcookie("default_school", $school, time()+3600);

That didn't work, so I did some searching, and found that I probably just needed to set a path, so I changed it to:

$school = "Some Value";
setcookie("default_school", $school, time()+3600, "/", ".mydomain.com");

That still didn't work so I did some more investigating, and determined that my issue must just me setting the cookie too late. So I then started checking my if my headers were set in certain parts of my code, which needs to return bool(false).


First the top of my index.php, then at the top of my header.php, but still the same result; they both return true?

I feel like this should be so simple, and I'm getting nowhere. A push in the right direction would be highly appreciated.

Thanks, Isaac

EDIT: Just tried putting it before the init hook, and it returned false. I then put the setcookie function there, and still no luck.

share|improve this question
up vote 3 down vote accepted

If you’re doing this via a theme, add this line to your functions.php file:

function set_user_cookie() {
    $school = "Some Value";
    setcookie('default_school', $school, time()+3600);
add_action( 'init', 'set_user_cookie');

To display information add this line

echo $_COOKIE['default_school']; 
share|improve this answer
Thanks, that did the trick. – iRector Oct 4 '12 at 7:02
The path and domain does not need to be set? – Damainman Oct 27 '13 at 22:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.