I have a wp_nav_menu showing pages, but I'd also like to include a log in/out link, based on the current state of the user, which will redirect them to the home page.

I've looked far and wide, but how can I implement this in a wp_nav_menu?

Thanks, Dennis


Use the wp_nav_menu_items hook to add a filter which will allow you to add your login / logout link.

Use wp_loginout() to display a status aware login / logout link. Codex page.

  • Is there any similar way to display 'register' link in top menu? – a_fan Nov 23 '11 at 12:11
  • Got it! Posted as a complementary answer. – a_fan Nov 23 '11 at 12:29

Use the following to display Register/Site Admin & Log in/Log out link in menu:

function show_register_login_link($nav) {
    // The "Register" link is not offered if the Administration > Settings > General > Membership: Anyone can register box is not checked.
    return $nav.wp_register("<li class='menu-item'>", "</li>", false)."<li class='menu-item'>".wp_loginout(get_site_url(), false)."</li>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.