Page 1 of 1

Adding a log in / log out link to menu

PostPosted: November 18th, 2011, 9:55 pm
by qblearning
I'm using s2member pro and a custom theme. I'm trying to add a simple log in / log out link to my site's main navigation menu. I stumbled upon this following code which I added to my functions.php file:

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;
}

It successfully added a log in / log out link to my menu. However, it does not adhere to the same login redirect rules that the s2member pro login widget adheres to. Has anyone attempted this?

Re: Adding a log in / log out link to menu

PostPosted: November 21st, 2011, 3:24 am
by Cristián Lávaque
It won't behave just like the widget, because the widget has its own settings that'll make the redirect be customized after each depending on how you configure it.

Code: Select all
wp_loginout('index.php'); 


That's telling it to redirect_to index.php after each login or logout, so this would prevent the user from being shown the Login Welcome page after login, for example. http://www.s2member.com/login-welcome-p ... cts-video/