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

why PHP $_session is not working in wordpress my php code is

$_SESSION['lang_opt'] = $_POST['lang_opt'];
$mylang = $_SESSION['lang_opt']; 
echo $mylang;
share|improve this question
where are you calling this code? – Bainternet Apr 7 '12 at 11:45
are you testing this on live server? – R T Aug 7 '15 at 11:55

Yes, you must use a small change for use session in WordPress.

if ( ! session_id() ) session_start();

Better you use a custom function

function my_start_session() {

@session_cache_limiter('private, must-revalidate'); //private_no_expire

*Please edit, I write from a mobile

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.