Reply To: Login, Register, Lost Password links
When I use this code without the
if(is_bbpress() && $args->theme_location == 'sub-header-menu')
it works but I get the links on both menus. Below is the code I tried to use for the second menu only – the second menu is called Logins – I tried to use both sub-header-menu or logins.
I tried your suggestion with both as well.
add_filter( 'wp_nav_menu_items', 'my_nav_menu_login_link' );
function my_nav_menu_login_link($menu) {
//uncomment the next line if you only want login on bbpress pages
if(is_bbpress() && $args->theme_location == 'sub-header-menu')
if (is_user_logged_in()) {
//set the $url on the next line to the page you want users to go back to when they logout
$url = '$url = 'http://www.mysite.com/forums';
$url2=wp_logout_url($url) ;
$loginlink = '<li><a title="Logout" href="'.$url2.'">Logout</a></li>';
}
else {
$current_user = wp_get_current_user();
$user=$current_user->user_login ;
//set $page on the next line = the permalink for your login page
$page=''login' ;
$loginlink = '<li><a href="/'.$page.'/">Login</a></li>';
}
//uncomment out the next lines if you only want login on bbpress pages
}
else {
$loginlink="" ;
}
$menu = $menu . $loginlink;
return $menu;
}