How to Enable Sessions in WordPress

14 September 2011 by Rick ~ 0 Comments 692 views

The Issue

Let’s say you want to use something like this in your theme or plugin:

$_SESSION['my_var'] = "Hello World!";

It might be actually not working.

The Solution

Paste de following line in your functions.php file of your theme:

if ( !session_id() )
add_action( 'init', 'session_start' );

Subscribe by E-mail:

« »
Add a Comment

Use [code] example piece of code [/code] to insert code into your comment.