WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Move login/logout to beginning of menu? (12 posts)

  1. rwilki
    Member
    Posted 12 months ago #

    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;
    }
  2. Andrew Nevins
    Barrel Rider, Spam Zapper & Volunteer Moderator
    Posted 12 months ago #

    Can you float the menu right instead, using CSS?

  3. rwilki
    Member
    Posted 12 months ago #

    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

  4. Andrew Nevins
    Barrel Rider, Spam Zapper & Volunteer Moderator
    Posted 12 months ago #

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

  5. rwilki
    Member
    Posted 12 months ago #

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

  6. Andrew Nevins
    Barrel Rider, Spam Zapper & Volunteer Moderator
    Posted 12 months ago #

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

  7. rwilki
    Member
    Posted 12 months ago #

    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

  8. Andrew Nevins
    Barrel Rider, Spam Zapper & Volunteer Moderator
    Posted 12 months ago #

    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;
    }
  9. Andrew Nevins
    Barrel Rider, Spam Zapper & Volunteer Moderator
    Posted 12 months ago #

    There was something else to add... 1 sec

  10. rwilki
    Member
    Posted 12 months ago #

    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;}
  11. Andrew Nevins
    Barrel Rider, Spam Zapper & Volunteer Moderator
    Posted 12 months ago #

    Good :)

  12. rwilki
    Member
    Posted 12 months ago #

    you are awesome Andrew thanks!!!

Reply

You must log in to post.

About this Topic

Tags