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

$_SESSION['lang_opt'] = $_POST['lang_opt'];
$mylang = $_SESSION['lang_opt']; 
echo $mylang;
  • where are you calling this code?
    – Bainternet
    Apr 7, 2012 at 11:45
  • are you testing this on live server?
    – R T
    Aug 7, 2015 at 11:55

1 Answer 1


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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