How to Add Login Session to Your WordPress Website

Last modified 16th June 2017


Here is the simple way,

Go to your admin page and click on Editor from Appearance menu.

Check for functions.php and add/edit it with the below code,

 

//Login Session Coding

add_filter(‘wp_nav_menu_items’, ‘add_login_logout_link’, 10, 2);
function add_login_logout_link($items, $args) {
ob_start();
wp_loginout(‘index.php’);
$loginoutlink = ob_get_contents();
ob_end_clean();
$items .= ‘<li>’. $loginoutlink .'</li>’;
return $items;
}

Once this is added to functions.php, your primary and secondary both menus will display the session status.

Thanks