Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Login, Register, Lost Password links

@robkk

Moderator

This should show the items in the specific menu.

add_filter( 'wp_nav_menu_items', 'rkk_add_auth_links', 10 , 2 );
function rkk_add_auth_links( $items, $args ) {
    if (is_user_logged_in() && $args->theme_location == 'sub-header-menu') {
        $items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
    }
    elseif (!is_user_logged_in() && $args->theme_location == 'sub-header-menu') {
        $items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
        $items .= '<li><a href="'. site_url('wp-login.php?action=register') .'">Register</a></li>';
        $items .= '<li><a href="'. site_url('wp-login.php?action=lostpassword') .'">Lost Password</a></li>';
    }
    return $items;
}

By default it leads to the regular wordpress login form. if you want to change that to a frontend page, you can change this site_url('wp-login.php') to something like this site_url('/login/').

login redirect you would need to use something like this.

function rkk_login_redirect($redirect_to, $request, $user) {
    return (is_array($user->roles) && in_array('administrator', $user->roles)) ? admin_url() : site_url('/forums/');
} 
add_filter('login_redirect', 'rkk_login_redirect', 10, 3);

This login redirect code redirect admins to the WordPress backend, but anything else to the forums.

Skip to toolbar