Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Show login greeting above sub-menu links?

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 use first_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/

Related Posts:

  1. How to place login logout link on menu that redirects users back to current page?
  2. How to display conditional-content if wp_nav_menu( $args ) retruns something
  3. WordPress Quick Question . How to Get Parent Link in Submenu in My Code
  4. get_the_title() gets printed out twice
  5. How to use wp_nav_menu to create custom dropdown menu?
  6. Remove submenu item from list
  7. Menu not updating for logged in users after redirect
  8. Get Child of Child Pages in custom Menu
  9. Display specific main Sub Nav on Woocommerce product pages
  10. Beyond widget side menu editing, with the php page, custom template
  11. How I can add div to menu?
  12. wp_nav_menu prints children with parent name
  13. Can’t remove menu items added by plugin
  14. Submenu opened problem
  15. How to add an arrow to menu items has submenus
  16. wp_nav_menu returns menu list in ascending order. How can I arrange the menu same as dashboard menu
  17. getting logged in user info (wp-load.php) from parent directory
  18. Unique icons next to each WordPress menu item
  19. Child page menu in sidebar
  20. Title Case WordPress Menu Items
  21. Secondary navigation menu on one page
  22. Remove class in nav_menu_link_attibutes filter
  23. How to target grandchild of post_parent using wp_list_pages
  24. Trying to store submenu items to render out after main menu
  25. Detecting classes, adding widgets, and adding divs in with a Nav Walker
  26. Problem with login form
  27. How to change menu order item
  28. Login to wordpress by clicking a link and specifying usernaname and password in url
  29. Custom Menus: dynamic highlighting problem with custom home link
  30. Log in / Log Out Custom Button
  31. Add item to top of menu using a filter in functions.php
  32. Should `wp_login` be used since it’s deprecated?
  33. How to redirect users based on role and content of redirect_to?
  34. Change CSS based on is_user_logged_in
  35. Adding PHP in the menu
  36. Two menus show up
  37. How to display login form anywhere, when user isn’t logged in, without redirecting?
  38. How can I open up my administrative panel to everyone?
  39. Register a menu – Error Header
  40. How to style one item from main navigation?
  41. Show About and Contact Us page when they’re clicked in the top menu.
  42. New walker for walker_nav_menu to change inside container data
  43. Add data-id attribute to child page links
  44. Parsing Menu Items and Blog Posts
  45. Add login hyperlink to secondary navigation menu
  46. Automatically add images to a menu
  47. How can I add a new row in a separate database when someone registers via WordPress?
  48. Add value to new attribute inside WordPress menu items
  49. wp_nav_menu not working correctly in my underscores theme
  50. One account with multiple logins
  51. Lost in trying to create user database system
  52. Add Login/Logout Menu Item to Primary Nav “My Account” Submenu [Woocommerce] [closed]
  53. Menu Items fail to save correctly, cause reset of related page metadata
  54. Dropdown menu for categories
  55. Menu Custom Data Attributes
  56. How to display different submenus?
  57. Get the name of menu item with wp_nav_menu
  58. Notice: Trying to get property of non-object
  59. Shortcode to log user into current URL
  60. How to modify mobile nav menu text in theme
  61. Get parents child pages
  62. Output only links using wp_nav_menu()
  63. Get css class of menu item in custom menu structure
  64. How to add aria role and schema markup to custom walker container
  65. PHP getting error when trying to access WP-Admin Dashboard
  66. How can I use custom menus with a Bootstrap WordPress theme?
  67. Nav menu from plugin to theme
  68. Adding Additional Variables on Menus Page
  69. I installed WordPress locally now how do I login?
  70. If user is logged in not working
  71. Change homepage content if user is logged in – BuddyPress
  72. Extend Menu Walker Output
  73. Nav-Menu not showing up
  74. Custom navigation menu with awsAccordion
  75. how to add a div inside wp_page_menu
  76. How to correctly load a different version of main menu based on the user language in WordPress? Is it a good solution?
  77. Why in this WordPress theme I can’t see the Main Menu?
  78. Why can’t I add a custom image in my navigation?
  79. conditional: if is page, and all subpages
  80. wp nav menu: show submenu below li item
  81. How to tell if a user has gone in and created a menu
  82. Dynamic Menu drops pages?
  83. Class for Selected Menu using wp_nav_menu
  84. is_user_logged_in returning nothing on custom page
  85. Remove the Tag from wp_nav_menu
  86. Menu not styling. New menus functionality giving me a headache
  87. Styling an “active” link outside of WordPress default menu
  88. How to create Loop code for Menu using WordPress?
  89. Hard-coding a shortcode as the last menu item in primary navigation?
  90. Dynamic menu with custom post types
  91. Help with accessing wp-admin page and resolving error messages
  92. Add class to ul and li in wp_na
  93. Nav Walker that shows only children and siblings of top level parent menu item
  94. how to changes mobile menu toggle breakpoint in WordPress
  95. How to display already created menus via php?
  96. Adding an Anchor Link to a wordpress menu using WPBakery Page Builder
  97. Providin exception to WordPress wp_nav_menu Custom CSS Classes
  98. Removing “There is no account with that username or email address.” error message in “/wp-login.php?action=lostpassword”
  99. Can’t log in to WordPress wp-admin after adding code to functions.php
  100. Adding markup to sub menu based on class
Categories PHP Tags login, menus, php, sub-menu
how to hide home nav link in wordpress
How can I reorder admin bar items?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress