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

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Can you float the menu right instead, using CSS?

    Thread Starter rwilki

    (@rwilki)

    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

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

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

    Thread Starter rwilki

    (@rwilki)

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

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

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

    Thread Starter rwilki

    (@rwilki)

    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

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    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;
    }

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    There was something else to add… 1 sec

    Thread Starter rwilki

    (@rwilki)

    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;}

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Good ??

    Thread Starter rwilki

    (@rwilki)

    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.