Mobile-Menu iFuturz Infoweb Inc. Contact Portfolio

27

Sep

Start session in WordPress

Start session in WordPress

Posted On : September 27, 2013

| No Comment

WordPress does not use sessions to hold any data. So in order to activate session variables within your WordPress installation the only thing you have to do is call session_start(); before any output is send to the client.

For start session in wordpress , you would add some code like below to your plugin or your theme’s

1
2
3
4
5
6
7
8
functions.php file.
add_action('init', 'startSessioninwordpress', 1);
 
function startSessioninwordpress() {
    if(!session_id()) {
        session_start();
    }
}

This code starts the session, the 1 is the priority to cause this to run before other initialization. The session will be available once this has run.

  • Tags:

Comment