Archived topic
Footer bar and secondary navigation
12 replies · Started by Jamal on June 12, 2017
Hi
I would like to add a Login/Logout link to the footer bar by adding a custom menu with this code added in code snippets. When the secondary navigation is set to below/above header the login/logout appears alright but not when i put the secondary nav in the footer bar. Anyway to get a Login/Logout link on my footer? Currently i just have copyright text and no footer widgets. Thanks
I believe you would have to register a new theme location: https://codex.wordpress.org/Function_Reference/register_nav_menus
Then update "secondary" in your code with whatever you named it.
Let me know if you need more info :)
Seems not to be working. I registered new location with this
register_nav_menus( array(
'footer_menu' => 'Login menu',
) );
and replaced "secondary" with both "Login" and "Login menu". Anyway i can use generate_before_footer to do something like below, having them left and right aligned respectively?
Some plain text || Login
I took another option of editing the deafult meta widget so only login link remains and it works as far as i can tell. https://wordpress.org/support/topic/edit-meta-widget-in-theme-file/
Thanks
Did you put it inside the after_setup_theme hook?
add_action( 'after_setup_theme','tu_register_custom_menu' );
function tu_register_custom_menu() {
register_nav_menus( array(
'footer_menu' => 'Login menu',
) );
}
Then you would have to apply your custom menu to that theme location in Appearance > Menus.
Doesn't seem to be working even after putting it after_setup_theme hook. Below is full code i have
//Register custom menu
add_action( 'after_setup_theme','jam_register_custom_menu' );
function jam_register_custom_menu() {
register_nav_menus( array(
'footer_menu' => 'Login menu',
) );
}
// Add login/logout to the custom menu
function add_login_logout_register_menu( $items, $args ) {
if ( $args->theme_location != 'Login menu' ) {
return $items;
}
if ( is_user_logged_in() ) {
$items .= '<li><a href="' . wp_logout_url() . '">' . __( 'Logga Ut' ) . '</a></li>';
} else {
$items .= '<li><a href="' . wp_login_url() . '">' . __( 'Logga In' ) . '</a></li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'add_login_logout_register_menu', 199, 2 );
I have added a few other items to the custom menu http://i.imgur.com/Qam0M9p.png
Added the custom menu widget to the footer bar http://i.imgur.com/zqa6dSW.png
But it doesn't show on the site http://i.imgur.com/TsvEMAp.png
Thanks for taking a look at this, would love to get it working using this method.
In the $args->theme_location check, you want to use: footer_menu
No luck with that as well, Tom. Must be combination of footer bar and custom menu widget because even when using the secondary navigation as i was doing in first post it wasn't working.
Strange - are those the only menu items you're wanting to add, or do you want others in there as well?
Just a login/logout link.
Perhaps just stick this into a text widget?: https://en-ca.wordpress.org/plugins/login-logout-shortcode/
I had to mull over it but in the end i went with your plugin suggestion and it works great. Thanks !
No problem! :)