Navigation bar item order

Support Area Forums Elite Navigation bar item order

Viewing 3 posts - 1 through 3 (of 3 total)
URL to the page in question: http://
  • Author
    Posts
  • #24619
    slurp
    Participant

    Hi!

    As you have probably noticed, I am now working quite a bit on my Elite site — constantly asking questions here… 😀 Sorry about that.

    I wanted to have a login button that would automatically turn into a logout button, once the user is logged in. I found and added this code into the child theme functions.php:

    //Login-logout menu item

    function add_login_logout_link($items, $args)
    {
    if(is_user_logged_in())
    {
    $newitems = ‘

  • Kirjaudu ulos
  • ‘;
    $newitems .= $items;
    }
    else
    {
    $newitems = ‘

  • Kirjaudu
  • ‘;
    $newitems .= $items;
    }
    return $newitems;
    }
    add_filter(‘wp_nav_menu_items’, ‘add_login_logout_link’, 10, 2);

    I can manage to get its position entirely to the right or left with the float command, but is there a way to get it somewhere inbetween the menu items that are added through the WP menu settings?

    Thank you!

    #24621
    Bill Robbins
    Moderator

    Questions are fine…no problem there.

    You could use some absolute positioning to place the login between other existing items if you need to. The only thing that would be tricky there is login and logout are slightly different size wise by a few pixels.

    Here’s anther thought. There is a plugin called Nav Menu Roles (https://wordpress.org/plugins/nav-menu-roles/) that lets you display/hide navigation menu items based on the user’s WordPress role. What you could do is create two links, one for login, one for logout. Then display the login one for users with no role (those who aren’t logged in). For anyone with a role (those logged in) you would hide the login button and display the logout.

    I haven’t tried that, but that might be an option and it’ll work on the mobile menu too.

    Bill

    #24637
    slurp
    Participant

    Hi!

    Thanks for the quick reply!

    I have the Nav Menu Roles installed and tried that before adding the custom function. The problem with that is adding the custom link to the menu. With logging in it’s fine, but logging out one would need to create a unique WP nonce to identify the logout. This I couldn’t manage to include in the custom link in the menu setting, because I couldn’t get the php to work inside the custom link field. Do you have any ideas, how this could be achieved?

    Thanks in advance!:)

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Navigation bar item order’ is closed to new replies.