From your code it seems like you are using this modal login plugin http://wordpress.org/plugins/wp-modal-login/ Considering this, I am providing the necessary code to add the menu item to the menu.
You need to use the wp_nav_menu_items
hook as below inside functions.php
file of your active theme.
// Add the hook to the nav menu items
add_filter( 'wp_nav_menu_items', 'wti_loginout_menu_link', 10, 2 );
function wti_loginout_menu_link( $items, $args ) {
// Get the global object for user and the modal login class
global $current_user, $wp_modal_login_class;
if ( $args->theme_location == 'primary' ) {
$items .= '<li>';
if ( is_user_logged_in() ) {
$items .= 'Welcome, ' . $current_user->user_nicename;
} else {
$items .= 'Welcome, visitor';
}
// Add the modal menu to the nav menu
$items .= ' ' . $wp_modal_login_class->modal_login_btn( 'Login', 'Logout', '', false );
$items .= '</li>';
}
return $items;
}
Few things to note:
-
The above code works with
primary
theme location. You need to change this to your theme location. -
I am using
user_nicename
, you can usefirst_name
of the user object as per your code.
The above hook is also discussed here http://www.webtechideas.com/adding-login-logout-link-to-wordpress-menu/