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

Add Login and logout buttons to top menu bar

“PRIMARY” and “secondary” menu bar really don’t mean anything when used out of context and without explanation. However, (guessing a lot) if your menus are constructed consistently you should be able to find the ‘name’ of the second menu and add a condition like (overly formatted for readability):

if (
  is_user_logged_in() 
  && (
    $args->theme_location == 'menu_top' 
    || $args->theme_location == 'other_menu_name'
  )
) { 
    $items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';

Same with the elseif.

Look for a call to wp_nav_menu in your theme files to find the ‘name’ of the second menu.

Related Posts:

  1. Masking logout URL
  2. Add Login/Logout Menu Item to Primary Nav “My Account” Submenu [Woocommerce] [closed]
  3. Logout Redirect and also WP-login.php Redirect
  4. wp_enqueue_script was called incorrectly
  5. Remove a menu item created by a plugin
  6. Logout redirect to current page – function
  7. Logout/login redirect CSS issue
  8. How can I tell if I’m on a login page? [duplicate]
  9. Is it possible to use a forgot password url filter?
  10. redirect wp-login.php to another page
  11. Login using the password from protected pages
  12. automatically adding submenu items
  13. How do I redirect upon login a specific user based on role?
  14. Logging in redirects to correct page but shows logged out content until forced refresh
  15. Remove default user registration, login and subscriber profiles
  16. is_user_logged_in not working to redirect only logged out users
  17. Logout hyperlink within a sub-menu
  18. Members only site – still need the lost password page accessible
  19. How to change login labels
  20. Login/logout in header
  21. How can I get my Script to work on the Login page?
  22. Login Redirect if Logged in from Specific Page
  23. Custom Nav Walker sub-menu
  24. Unable to login using username
  25. When a user logs in, how can they view the website instead of the admin menu?
  26. WordPress PHP Conflicting User Sessions
  27. Get User Login Data (date, time… )
  28. Registration Hooks don’t appear to be working
  29. If user is logged-in display/hide something
  30. retrieves menu and converts it to a readable array
  31. Secondary Menu and Logged In Users
  32. Prevent WordPress Automatic Logout
  33. error at login page in wordpress
  34. why is this function firing on all child menu items as well?
  35. How to hightlight all ancestor menu items of a child page NOT displayed in menu
  36. loginout function customization
  37. Unable to add extra elements to the main navi (wp_nav_menu_items)
  38. Show errormessages on wrong username/password on custom loginform?
  39. Conditional custom menu?
  40. WordPress login set cookie that survive browser exit (wp_signon function)
  41. This code is supposed to only allow user to be authenticated if accountVerified is equal to 1, but it still allows user to be authenticated otherwise
  42. Prevent wp_signon redirect on failed login for ajax login
  43. How to redirect Subscribers on login to specific page, when logging in from a Page
  44. How to replace ACTION url from original wordpress login form?
  45. Unable to login after registration
  46. Allow logged in user to view a Page, else send to login screen and then redirect back to Page
  47. Redirect after login to current URL
  48. Login functions
  49. WordPress permanently logging users out
  50. Modify sub_menu function to show pages below a specifically set page
  51. How to request login for user but not for bots
  52. is_user_logged_in() isn’t working
  53. How do I get my nav menu to show sub pages?
  54. update_user_option not working as expected
  55. “Headers already sent” while trying to add a CSS file to my login page?
  56. Logout redirect via page template without confirmation?
  57. Simple way to make most of my site private
  58. wp_login_form display no styled form
  59. Redirecting after login except for a specific page
  60. wp enqueue style on about us page
  61. CF7 select value get to function and reciept value from function
  62. wp_get_current_user return ID = 0 when used outside of wordpress, such as webhook / fulfillment dialogflow
  63. Fatal error: Call to undefined function load_theme_textdomain() in /var/www/vhosts/61/151172/webspace/httpdocs/wp-includes/functions.php on line 5
  64. large image size of 1440×1440 not pulling 2x of 2880×2880 image
  65. Hide author info in single posts by certain users
  66. How to reference different css (bootstrap) stylesheets for the header and body of a page?
  67. Creating a custom functions page wordpress
  68. Remove text after a dot and a colon in Woocommerce product title
  69. sort title descending with title with number
  70. Delete oldest wordpress post (SQL query)
  71. Add #primary at the end of navlink permalinks on single posts
  72. search and replace using regex
  73. post value to function with Ajax and jQuery
  74. When are the user meta fields created in the database? Admin vs Woo API REST
  75. Selecting specific query for offset
  76. Enqueue script if not page template
  77. External api call and make global variable for any page visitor enters , page-home, page, single etc
  78. Is_Page doesnt detect my page
  79. How do you insert code into the sidebar?
  80. How Do I Unhook This Parent Theme Function?
  81. price of product can’t return when get data of product in functions.php
  82. Including Font Awesome in a Custom Theme
  83. remove_filter function to unhook twentysixteen parent theme function
  84. WP AJAX Request Not Working
  85. Test CDN link from function.php or wp_enqueue_script/style?
  86. Problem with is_user_logged_in() function in some pages
  87. Woocommerce product price change
  88. Remove the ‘category’ url for one category type
  89. Can we have conditional CSS styling?
  90. CSS style and app.js not loading
  91. Change function without filter hook
  92. Security when outputing wp_oembed_get code
  93. Help with with my function for wordpress
  94. Widget is displayed in two places
  95. Allow user only create specific tags
  96. is_email gives me error
  97. Trying to change widgets h-tags
  98. only update titles of single posts
  99. Post content overflows on my mobile phone
  100. Stylesheet does not load despite functions.php
Categories functions Tags functions, login, logout, sub-menu
Is the front-page.php template reserved in wordpress twenty twelve theme?
How to use the empty space left and right of a post?

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