Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers

up vote 4 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? –  afnrf Nov 23 '11 at 12:11
    
Got it! Posted as a complementary answer. –  afnrf Nov 23 '11 at 12:29
add comment

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

add_filter('wp_nav_menu_items','show_register_login_link');
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
add comment

Your Answer

 
discard

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.