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)
  • Moderator Andrew Nevins

    (@anevins)

    Forum moderator

    Can you float the menu right instead, using CSS?

    thanks Andrew. I wish I could use css, but the menu is already floated:right and I don’t think that’ll work. for some reason, it’s still adding my new menu item (login) after the secondary menu. I’m guessing that’s because of a higher priority?

    thanks,
    Bob

    Moderator Andrew Nevins

    (@anevins)

    Forum moderator

    Are you working locally? If not, may you link the site?

    Thanks Andrew. Just sent you an email from your website.
    Bob

    Moderator Andrew Nevins

    (@anevins)

    Forum moderator

    Is this what you’re trying to do http://awesomescreenshot.com/0ea174b810 ?

    absolutely! I’m afraid absolute positioning won’t work because the login link changes depending upon your status. maybe you have another idea?

    thanks,
    bob

    Moderator Andrew Nevins

    (@anevins)

    Forum moderator

    Can you add this CSS;

    .memby {
     float: left;
    }
    
    #top-menu li {
     margin-right: 10px;
     padding-right: 10px;
     margin-left: 0;
     padding-left: 0;
     border-left: 0;
     border-right: solid 1px #f1f1f1;
    }

    Moderator Andrew Nevins

    (@anevins)

    Forum moderator

    There was something else to add… 1 sec

    no worries… thanks so much for your help.

    I think I got it with the following:

    .memby {
    float: left;}
    
    #top-menu li {
    display:inline;
    margin-right: 10px;
    padding-right: 10px;
    margin-left: 0;
    border-right:1px solid #ccc;
    padding-left: 0;}
    
    #top-menu li:first-child {padding-left: 0;}
    #top-menu li:last-child {border:none;padding-right:0;margin-right:0;}

    Moderator Andrew Nevins

    (@anevins)

    Forum moderator

    Good 🙂

    you are awesome Andrew thanks!!!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Move login/logout to beginning of menu?’ is closed to new replies.