I am using the following code to add Log In and Log Out links in the Primary Menu. Can't give a web link because the site is still under construction.
//* Add a Login/Logout toggle item in WordPress navigation menu
add_filter('wp_nav_menu_items', 'customprefix_add_loginout_navitem', 10, 2);
function customprefix_add_loginout_navitem($items, $args) {
if ($args->theme_location == 'primary') {
// Replace "primary" with your theme's menu name
if (!(is_user_logged_in())) {
$login_item = '<li class="menu-item login-menu-item"><a itemprop="url" href="/wp-login.php" rel="nofollow">Log in</a></li>';
} else {
$login_item = '<li class="menu-item logout-menu-item">' . wp_loginout($_SERVER['REQUEST_URI'], false) . '</li>';
}
$items.= $login_item;
}
return $items;
}
The problem is this: The logout link works properly in the membership area of the site, but if someone has logged in to the membership area and wants to browse to the normal public pages, the logout link randomly disappears on the public pages and is replaced with the login link. This means the user has to login again to get back to the membership pages. Not a good thing.
In other words, the logout link sometimes shows on the public pages and sometimes it doesn't. This happens most frequently on the home page, but in general it effects all public pages.
So, my question is:
After a user has logged in, how can I make the logout link show on all pages (both public & membership) until the user is ready to logout? I do not want to make them login again.
By the way, I tried at least 6 WordPress plugins to get the login/logout links to work properly before I went to the PHP option. All the plugins have had the same issue of not showing the logout link on all pages until the user is ready to log out.
Hope someone can help.
Thanks,