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

Use another menu when logged in

Actually, all I need is to change one specific button in the menu, so
it is different when the user is logged in – in that case that menu
button will be a “Member profile” button instead of a “Log in” button

Yes, you can use only one menu, assuming its slug is ‘my_menu’ do not add to it member profile nor login url, instead use wp_nav_menu_{$menu_slug}_items filter:

// 'my_menu' in filter name is the slug of the menu
add_filter('wp_nav_menu_my_menu_items', 'menu_add_admin_buttons', 20, 2); 

function menu_add_admin_buttons( $items, $args ) {
  $btn_format="<li><a href="https://wordpress.stackexchange.com/questions/112324/%s">%s</a></li>";
  if ( is_user_logged_in() ) {
    $btn = sprintf($btn_format, admin_url('profile.php'), __('Your Profile') );
  } else {
    $btn = sprintf($btn_format, wp_login_url(), __('Log In') );
  }
  return $items . $btn;
}

$items are the current html for the current menu items, a string containg a series of <li><a ... </a></li>.

The slug of the menu is equal to sanitize_title($menu_name) i.e. it removes all special chars, converted accented chars with non accented ones and convert spaces to -.

E.g. if the name is “Main Menu” the slug is “main-menu”.

The name your menu is called is what you write in wp backend when you create menu, see image below.

enter image description here

Of course is possible use sanitize_title to create the filter dinamically from name, e.g.

$menu_filter="wp_nav_menu_" . sanitize_title("Main Menu") . '_items';
add_filter($menu_filter, 'menu_add_admin_buttons', 20, 2); 

Related Posts:

  1. Add “Logout” link to navigation menu
  2. Add a logout menu link [duplicate]
  3. Add log in link to menu in Twenty Twelve
  4. add the user name to menu when user is logged in [closed]
  5. wp_nav_menu log in/out link?
  6. Making WordPress’ page and menus visible only for logged in users, checking session variables
  7. Show menu item only if user is logged In (not word press login)
  8. How to Show Different Menus to Logged in Users in WordPress [duplicate]
  9. login logout menu changes in wordpress [closed]
  10. WordPress Login/Logout Single Menu Only
  11. How to add Loginout to Sub-menu
  12. How to make Logout Link consistently appear on all web pages?
  13. Change “login/register” to “useraccount” when a user has logged in
  14. Display a portion/ branch of the menu tree using wp_nav_menu()
  15. Programmatically add a Navigation menu and menu items
  16. Any docs for wp_nav_menu’s “items_wrap” argument?
  17. Customizing Only a Specific Menu using the “wp_nav_menu_items” Hook?
  18. Changing the Order of Admin Menu Sections?
  19. How make top level menu item not have link, but have sub-menus that are linked?
  20. Add ‘has_children’ class to parent li when modifying Walker_Nav_Menu
  21. Get WP Navigation Menu from REST API V2
  22. How to Hard Code Custom menu items
  23. How to add a Custom Link to a Menu with a URL that is relative to the blog URL
  24. How do I remove UL on wp_nav_menu?
  25. Retrieving a list of menu items in an array
  26. WordPress default menu in database
  27. Adding an Arbitrary Link to the Admin Menu?
  28. Dynamically exclude menu items from wp_nav_menu
  29. Error: Declaration of MyClass::start_lvl() should be compatible with that of Walker_Nav_Menu::start_lvl()
  30. Split up wp_nav_menu with custom walker
  31. Removing container from wp_nav_menu not working
  32. Custom Nav walker display current menu item children, or siblings on no children
  33. wp_nav_menu: show menu only if one exists, otherwise show nothing
  34. Is there an easy way to replace a custom menu link with a page or post?
  35. Convert output of nav_menu items into a tree-like multidimensional array
  36. Get page IDs from nav items
  37. Add a custom walker to a menu created in a widget
  38. Using a menu walker add a custom item at the end of the menu’s items
  39. Add settings to menu items in the Customizer
  40. wp_get_nav_menu_items() not working with slug
  41. How to get current-menu-item title as variable?
  42. Error “Trying to get property of non-object” with Custom Walker for wp_nav_menu
  43. Add Class to Specific Link in Custom Menu
  44. Remove a menu item in menu
  45. Generate a Menu that Displays Child Pages using wp_list_pages() with the New Menu Functionality in WordPress 3.0?
  46. How do I get the name of a menu in WordPress?
  47. How to Add to Each Menu Link with link text to data-attr?
  48. How to manually specify the current active page with wp_nav_menu()
  49. How to count nav menu items?
  50. How Does The Walker Class Work?
  51. Add Javascript to WordPress Menu
  52. Add custom menu item using wp_nav_menu_items filter
  53. Filter wp_nav_menu()
  54. How to modify navigation menu of the “My Account” page in WooCommerce
  55. remove “edit your profile” from admin menu bar
  56. WordPress Settings API, Implementing Tabs On Custom Menu Page
  57. Adding line breaks to nav menu items
  58. Adding category ID or slug to WP Nav Menu
  59. add custom class to wp_nav_menu using filter hook nav_menu_css_class
  60. Custom ID for certain menu item?
  61. Does Extending Multiple Nav_Menu_Walkers Allow Nested Menus?
  62. Check if page is in a certain menu
  63. how to create a menu with all sub categories?
  64. Making breadcrumb with wp_nav_menu
  65. Does WP REST API have a built in route for calling menu?
  66. How to avoid wp_nav_menu() ID conflict?
  67. Add data-icon input to WordPress custom menu links
  68. Registering menu with ‘Automatically add new top-level pages to this menu’ selected
  69. Why do Custom Nav Menus generate so many classes on list items? Can I manage this somehow?
  70. wp_nav_menu remove class and id from li
  71. Custom search filter causes menu and query_posts problems
  72. Unregister Nav Menu from Child-Theme
  73. How does a minimal menu walker look like?
  74. Add separator to admin submenu
  75. fall back for main menu?
  76. On which hook should I be calling register_nav_menu(s)?
  77. WordPress Shortcode in Menu Item Title
  78. register_nav_menus() won’t register menus
  79. Calling the Menu Title within wp_nav_menu array function
  80. How can I create an auto-populated menu that is automatically assigned to a location?
  81. Display only page specific sub menu items using Custom Walker
  82. How do I add a search box to the nav menu?
  83. How to get IDs for objects in menu branch?
  84. New post notification in wp_nav_menu
  85. Custom Post Types posts as submenus in Nav Menu
  86. Link to Author archive from Navigation Menus in dashboard?
  87. How to stop mobile theme inheriting desktop navigation menu?
  88. Add child pages automatically to nav menu
  89. adding some custom html code to the wp_nav_menu function
  90. WordPress Menu Custom Walker Class
  91. Show just one level of child pages, wp_list_pages woe
  92. Increase search results for Admin -> Appearance -> Menus -> Search (default is 10)
  93. How to create this custom menu walker?
  94. Removing link ” from ” menu for some “links” without JS
  95. How to change order of menu items
  96. Renaming a WordPress Admin Menu
  97. Whats the difference between current_page_item and current-menu-item
  98. Using nonce in menu item
  99. Remove unusable metaboxes in nav menu management screen
  100. Menu limit, cannot add new menu items
Categories menus Tags login, menus
cleaning up safely wordpress wp_postmeta table
How to disable accessing the custom post types from frontend via a link?

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