How to display logged in user name with avtar in Menu

If you added user Login / Register menu item in WP menu and want to hide it once user already logged in as well in place of Login / Signup want to display currently logged in user name with Profile / Avtar picture than current post become very helpful for you to easily achieve it with your wordpress website blog.

To hide Login, Register ( Sign up ) etc menu item when user already logged in and no need to display it than you can easily achieve it by using wordpress plugin If Menu

After Install and activate If menu – Display or hide menu items with conditions go to wp-admin > Appearance and do setting like given in below screenshot.


Now time to Dynamically add currently logged in user menu item with Display name and Avtar (Profile Picture ) by get_avatar function and wp_nav_menu_items woprdpress menu filter action .

add following code in your active theme function.php file

function ls_user_avtar_in_menu( $nav, $args ) 
     //echo $args->theme_location; 
     if( $args->theme_location == 'top_nav' ) 
          $current_user = wp_get_current_user();
	      return "
  • ".get_avatar( $current_user->ID, 20 ).' ' .$current_user->display_name."
  • "; } add_filter('wp_nav_menu_items','ls_user_avtar_in_menu', 10, 2); // top_nav is in my case theme menu location to display new menu item in only specific menu instead of all wp menu. if you want to find theme menu location with your theme than enable comment echo $args->theme_location;
    Scroll to Top