Login/Logout in Menu
-
Hi Guys
I have the following code in my functions.php for adding a login/logout to my menus
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; }I need to change the code so it only applies to my secondary menu that is registered like so.
function register_main_menus() { register_nav_menus( array( 'primary-menu' => __( 'Primary Menu' ), 'secondary-menu' => __( 'Second Menu' ) ) ); }How can I apply this login/logout code to just the Secondary Menu?
Part 2…
I’d also like to be able to select the order it is placed in. Right now I need it added to the end of the menu items.Thanks
-
ok I was able to get it to just display on my second menu by doing this
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(); if( $args->theme_location == 'secondary-menu' ){ $items .= '<li>'. $loginoutlink .'</li>'; } return $items; }Now how do I position it in the menu?
I’d also like to know how. Tried changing the priority number 10 to something else, but it didn’t work.
No extra coding is needed. Here is easy to use plugin – BAW Login/Logout menu:
http://ww.wp.xz.cn/extend/plugins/baw-login-logout-menu/
The topic ‘Login/Logout in Menu’ is closed to new replies.