I'm trying to add a menu conditional login/logout item to a menu that I registered in a child theme.
I registered the menu like this in the child theme's functions.php:
function awsm_navigation_menus() {
$locations = array(
'footer' => __( 'Footer Menu', 'text_domain' ),
'account' => __( 'Account Menu', 'text_domain' ),
);
register_nav_menus( $locations ); }
add_action( 'init', 'awsm_navigation_menus' );
And the code for the menu item is a little further down:
add_filter( 'wp_nav_menu_items', 'awsm_loginout_menu_link', 10, 2 );
function awsm_loginout_menu_link( $items, $args ) {
if ($args->theme_location == 'account') {
if (is_user_logged_in()) {
$items .= '<li class="right"><a href="'. wp_logout_url() .'">'. __("Log Out") .'</a></li>';
} else {
$items .= '<li class="right"><a href="'. wp_login_url(get_permalink()) .'">'. __("Log In") .'</a></li>';
}
}
return $items;
}
It is working when I use ($args->theme_location == 'primary') but I need it in my own menu.