Back to Top

How to manage Session in WordPress

WordPress is stateless open-source content management system so WordPress does not use sessions.This means that session is not initialized automatically in WordPress.If you want to use sessions in WordPress, WordPress you need to initialize the session manually.

Let’s have a look into following methods for enabling a seWordPress.

Method 1:

Config(wp-config.php) file is the Common place to initialize the session in wordpress.

Open your wp-config.php file and add the following line at the beginning of the file:

you can use session_start() in config.php, but it is not recommended.

Method 2:

Next Method, you can add following the line of code into functions.php. Here in this method,We use add_action( ‘init’,function_name ) which used to initialize and load plugins

Let’s have a look into the below function, I called by add_action and added session_start() so the session will be initialized and we can use it.

Recommended Read: Auto tagging in WordPress

Also Read: Post via e-mail in WordPress

Here, I have called one function that is wp_check_login and fist of all, I have started a session with session_start() .Now you can use sessions in WordPress.

That’s it.I hope this post will help you. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Leave a Reply

Your email address will not be published. Required fields are marked *

Most Popular Posts

To learn MySQL PACK_KEYS with example

Posted on 3 years ago

Bhumi

What are Traits in PHP

Posted on 2 years ago

Bhumi

How To Send Email in MODx

Posted on 5 years ago

Bhumi

How to detect browser in Joomla

Posted on 5 years ago

Bhumi

Overview of ECMAScript 6 new Features

Updated 18 years ago

Bhumi

Getting started with Amazon Web Services

Updated 18 years ago

Bhumi

Facade implementation in Laravel

Updated 18 years ago

Bhumi

The Reader’s Poll – June 2015

Posted on 2 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 3 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 4 years ago

Bhumi