WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 5 down vote accepted

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.

share|improve this answer
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>";
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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