Support » Fixing WordPress » Move login/logout to beginning of menu?

  • Resolved rwilki

    (@rwilki)


    I’ve been struggling with this and can’t figure out an answer.

    I’m using this code to add a login/logout url to one of my menus. But I’d like it to be at the beginning of the menu, not the end. I’m pretty sure it has to do with the priority of “10,2” but that’s all I got. Can anyone help?

    Thanks,
    Bob

    add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
    function add_loginout_link( $items, $args ) {
        if (is_user_logged_in() && $args->theme_location == 'secondary') {
            $items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
        }
        elseif (!is_user_logged_in() && $args->theme_location == 'primary') {
            $items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
        }
        return $items;
    }
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Move login/logout to beginning of menu?’ is closed to new replies.