Adding login/logout to thte menu
-
Hi,
In an attempt to add login/logout to my menu, I’ve added this code to my function.php
/* LogIn - LogOut */ add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2); function add_login_logout_link($items, $args) { ob_start(); wp_loginout('index.php'); $loginoutlink = ob_get_contents(); ob_end_clean(); $items .= '<li>'. $loginoutlink .'</li>'; return $items; } /* LogIn - LogOut END */My problem is, that the login/logout now appears in both the page menu as well as the category menu.
How do I make it appear only in the page menu?
Help greatly appreciated thank you,
Michael 🙂
-
Thank you t-p,
Well that was easy, and much more clever than the function.
But I use a very advanced theme and no matter how much I try to integrate the, yet very simple, MU Theme login, it doesn’t work for my theme.
I’ve tried it out on other themes with success, so it has to do with the theme for sure.
What I’ve done instead, is to add a costume link to the menu, but only to login.
Could anyone please tell me if it’s possible to program a costume link to work as BOTH login and logout?
Once again t-p, thank you for your help 🙂
Regards,
MichaelI did the same thing – added a login/out link with the function you show at the top.
And I had the same problem: all menus got the link, not just the one I wanted.
Here is the post with a function that lets you select the menu for the login/out link:
http://wpsmith.net/2011/tutorials/how-to-add-a-log-inlog-out-link-to-a-specific-custom-menu/
Well, that code from WP Smith didn’t work for me but this one did:
Good luck!
Here is a better and cleaner way to do it
http://xparkmedia.com/2012/04/add-login-logout-link-menu/No extra coding is needed. Here is easy to use plugin – BAW Login/Logout menu:
http://wordpress.org/extend/plugins/baw-login-logout-menu/
The topic ‘Adding login/logout to thte menu’ is closed to new replies.