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

WordPress Login/Logout Single Menu Only

Change the filter hook to wp_nav_menu_{menu-name}_items, so it will only run on a specific menu. For example, if the menu name is “Secondary”, use the hook wp_nav_menu_secondary_items, or if the menu name is “Top Navigation”, use wp_nav_menu_top-navigation_items (replace spaces in the menu name with dashes).

Your updated code, assuming the menu name is “Secondary” (the menu name, not the theme location), would be:

add_filter('wp_nav_menu_secondary_items', 'add_login_logout_link', 10, 2);
function add_login_logout_link($items, $args) {    
    ob_start();
    wp_loginout('index.php');
    $loginoutlink = ob_get_contents();
    ob_end_clean();         
    $items .= '<li>'. $loginoutlink .'</li>';    
    return $items;
}

Related Posts:

  1. Add a logout menu link [duplicate]
  2. add the user name to menu when user is logged in [closed]
  3. wp_nav_menu log in/out link?
  4. How to Show Different Menus to Logged in Users in WordPress [duplicate]
  5. login logout menu changes in wordpress [closed]
  6. How to add Loginout to Sub-menu
  7. How to make Logout Link consistently appear on all web pages?
  8. Add “Logout” link to navigation menu
  9. Add log in link to menu in Twenty Twelve
  10. Making WordPress’ page and menus visible only for logged in users, checking session variables
  11. Show menu item only if user is logged In (not word press login)
  12. do_action appearing outside of menu?
  13. Use wp_logout_url() in menu creation page
  14. Use another menu when logged in
  15. Change “login/register” to “useraccount” when a user has logged in
  16. To Add Logout Button in Menu [duplicate]
  17. Retrieving a list of menu items in an array
  18. Error: Declaration of MyClass::start_lvl() should be compatible with that of Walker_Nav_Menu::start_lvl()
  19. Using nonce in menu item
  20. Filter out built-in wp_nav_menu classes but keep custom class
  21. remove last separator?
  22. How to get a different mobile menu than desktop menu in the twentytwelve child theme
  23. WordPress built in breadcrumb trail menu?
  24. Custom Nav Walker menu – Display children count
  25. WordPress Export Import Site Navigation Menu
  26. Bar separated navigation by extending Walker_Nav_Menu
  27. WordPress Menu Disappears when $query->query_vars[‘meta_key’] is set
  28. how do I delete (not exclude) a menu item from navigation bar
  29. show only a given level in nav menu
  30. Custom menus created but does not show up in admin panel
  31. Replace menu tag with tag
  32. How to display custom post meta in the appearance->menus page
  33. Anchor only wp_nav_menu
  34. wp_nav_menu custom walker – child items
  35. Where do custom menus get constructed?
  36. How to remove div container in custom menu?
  37. Keeping ‘current-menu-item’ highlight of navigation menu?
  38. Does loading of sub pages in menu cause load to the server?
  39. Get admin menu link
  40. Possible to add a dynamic link to a sub-menu via wp_nav_menu_items?
  41. How can I access the menu ID of an element in a WordPress Nav_Walker
  42. Fragment URL in navigation item without a custom link
  43. How to translate menu items?
  44. Unable to create or edit menus
  45. How to Implement Submenu Using wp_nav_menu
  46. Close dropdown menu on click or scroll outside the menu [closed]
  47. How to have the Header show different content on different pages?
  48. WordPress menu not loading in the admin side appearence-> menu tab
  49. Is there no straightforward way to display a separate second level using wp_nav_menu()?
  50. CSS_Menu_Walker not showing on mobile view?
  51. HTML list menu to WordPress menu
  52. Filter Menu Items by Custom User Role in a page
  53. Add “drop-down arrow” for menu items with sub-menus
  54. Cannot seem to replace the native menu with the menu I created, so 2 menus appear
  55. Add span in top menu item with nested itens
  56. Secondary Navigation Menudisappeared When using wp_nav_menu_items
  57. Add Labels to Admin Menu ( How To )
  58. How to remove ‘wordpress…’ text from page titles in tabs
  59. Hide a menu on posts
  60. WP navigation list classes
  61. Can’t create a SubMenu
  62. unable to add custom page/tab to my account woocommerce
  63. Add Login/Logout Menu Item to Primary Nav “My Account” Submenu [Woocommerce] [closed]
  64. Add (grand)child pages automatically to nav menu
  65. Having trouble adding CSS class through menu to link
  66. Switch an entire nav menu if user is logged in
  67. Pull Menu Items Into an HTML element
  68. How to pass menu slug as a variable to wp_nav_menu?
  69. Add a string after each item in WordPress sub menu
  70. Add # to submenu URLs automatically
  71. Automatically Generated Menu pages
  72. Costum walker with sub menu item count
  73. Unable to nest categories in menu
  74. adding pages in underscores.me theme
  75. Trying to add Newline in Menu item
  76. How to unlock menu editing
  77. Can I now add a class in the anchor of my menu item with WordPress 5.4?
  78. How to add a taxonomy type in Menus?
  79. Header Navmenu glitching in Chrome (but not other browsers)
  80. how to display different menu according to postid?
  81. Homepage is not loading
  82. Disable Mobile Menu, (always show desktop menu)
  83. Put two menus in the same location
  84. Add Featured Image and Title to wp_nav_menu items
  85. Secondary Menu display Primary Menu
  86. Is it possible to separate all submenu items?
  87. Frontside menu based on custom roles logged in permission
  88. Reveal hidden submenus on page load – Twenty Fifteen theme
  89. Admin Custom Menu Editor Disappeared
  90. Hide menu theme location for certain capabilities?
  91. Making a Custom Menu Sidebar Icon show as Current in css [closed]
  92. Adding two submenus to a menu
  93. Change archive link to single post
  94. Remove from wp_nav_menu() wordpress
  95. collapse twenty twelve submenu in mobile version
  96. Styling Active Links Within WordPress
  97. Make title bar collapse when scrolling
  98. Problem with float:left – unexpected behavior [closed]
  99. Twenty-Twenty-Two Child Theme Mega Menu
  100. Whenever I add, modify, or remove a menu, my WordPress website does not update unless I perform a CSS regeneration. How can I address that problem?
Categories menus Tags login, logout, menus
Why the dynamic_sidebar() call is putted into an ul tag?
Is wp_deregister_script the best way to deal with unneeded plugins in a page?

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