• Resolved Benskh081

    (@benskh081)


    Hi im using this code:

    function add_login_logout_link($items, $args)
    {
      if(is_user_logged_in())
      {
        $newitems = $items;
        $newitems .= '<li><a title="Logout" href="'. wp_logout_url('index.php') .'">Logout</a></li>';
      }
      else
      {
        $newitems = $items;
        $newitems .= '<li><a title="Login" href="'. wp_login_url('wp-admin/index.php') .'">Login</a></li>';
      }
    
      return $newitems;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);

    It works but the problem is that it shows on both menus, how do I get to show it on a specific one?

    thank you
    /Ben

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter Benskh081

    (@benskh081)

    Moderator keesiemeijer

    (@keesiemeijer)

    It works but the problem is that it shows on both menus,

    What are the “both menus”?

    Thread Starter Benskh081

    (@benskh081)

    Em sorry I don’t follow the question, but they are called ′Main Navigation’ and ‘Top Navigation’.

    Im using the top nav for login and the main nav for links to other pages within the site.

    Moderator keesiemeijer

    (@keesiemeijer)

    Try with this

    function add_login_logout_link($items, $args)
    {
    if( $args->theme_location == 'Top Navigation' ) {
      if(is_user_logged_in())
      {
        $newitems = $items;
        $newitems .= '<li><a title="Logout" href="'. wp_logout_url('index.php') .'">Logout</a></li>';
      }
      else
      {
        $newitems = $items;
        $newitems .= '<li><a title="Login" href="'. wp_login_url('wp-admin/index.php') .'">Login</a></li>';
      }
    
      return $newitems;
     } else {
       return $items;
     }
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);

    Thread Starter Benskh081

    (@benskh081)

    thanks for your help, I really really apreciate your kindness.
    Sorry but It didnt work, Doesnt seems that it did find the ‘Top Navigation’ couse now both the login dissapeared.

    Thread Starter Benskh081

    (@benskh081)

    ah solved it, it was called ‘topNav’
    thousand thanks!

    Moderator keesiemeijer

    (@keesiemeijer)

    Glad you got it resolved.

    Thread Starter Benskh081

    (@benskh081)

    Is there a change to get the text when you are logged in to say ‘Welcome “username”? with that code?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Added login/logut to the nav bar but it shows on both nav.’ is closed to new replies.