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

So I'm trying to use a session to move a variable through pages. For some reason I literally cannot access anything from index.php to archive. I declare my session at the very top of my header.php like:

        $_SESSION['catID'] = 3;

Then I move to the archive.php which pulls in the header via <?php get_header() ?> and my session is suddenly gone. I try to echo it out and get nothing. Same thing happens with normal variables - like it's out of scope.

Anybody else have a similar problem or a solution?

share|improve this question
up vote 1 down vote accepted

In WordPress you need to start the session with

if ( !session_id() ) { session_start(); }

in order to use session variables. You can enter this code into wp-config

See http://www.frank-verhoeven.com/using-session-in-wordpress

share|improve this answer

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.