Archived topic
Login/out and register links in submenu
7 replies · Started by Max on August 28, 2017
Hey
I am using the following snippet to have login/0ut and register links in my main menu.
///////////// LOGIN AND REGO /////////////////////////////////
// LOGINOUT AND REGO LINK IN MAIN MENU
function add_login_logout_register_menu( $items, $args ) {
if ( $args->theme_location != 'primary' ) {
return $items;
}
if ( is_user_logged_in() ) {
$items .= '<li><a href="' . wp_logout_url() . '">' . __( 'Log Out' ) . '</a></li>';
} else {
$items .= '<li><a href="' . wp_login_url() . '">' . __( 'Login In' ) . '</a></li>';
$items .= '<li><a href="' . wp_registration_url() . '">' . __( 'Register' ) . '</a></li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'add_login_logout_register_menu', 199, 2 );
// END LOGINOUT IN MENU
I have too many tab on my navigation and so I would like to put the login/out and Register links as submenu items under a single nav tab called Members.
What tweaks to the above snippet are required to achieve this.
Thanks in advance for your help.
I'm not sure if it's possible to add sub-menu items using a filter like that.
You would likely need to use a plugin.
This is the only one I could find: https://en-ca.wordpress.org/plugins/baw-login-logout-menu/
It hasn't been updated in a while, but there's still 40,000+ people using it.
Hi, I noticed that on your website you have a nice solution with Log In link and then Log Out/Downloads links within Account menu item if a user is logged in. Do you use the plugin you mentioned in the earlier post or this is some custom code? I'd like to use the same approach.
Thanks.
We are using Easy Digital Downloads :)
Hi Leo, but do you use this tool to create this Log in / Log out links in the menu? I was asking about the menu just in case.
One of these plugins should help:
https://wordpress.org/plugins/login-or-logout-menu-item/
https://wordpress.org/plugins/login-logout-menu/
Nice, thanks!
No problem :)