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 menu item only if user is logged In (not word press login)

Use the wp_nav_menu_objects filter to access the menu items

I have used this code:

add_filter('wp_nav_menu_objects', 'ad_filter_menu', 10, 2);

function ad_filter_menu($sorted_menu_objects, $args) {
    // check for the right menu to rename the menu item from
    // here we check for theme location of 'primary-menu'
    // alternatively you can check for menu name ($args->menu == 'menu_name')

    if ($args->theme_location != 'primary')  
        return $sorted_menu_objects;

    // rename the menu item that has a title of 'Log ind'
        if (is_user_logged_in()) {
            foreach ($sorted_menu_objects as $key => $menu_object) {
                // can also check for $menu_object->url for example
                // see all properties to test against:
                // print_r($menu_object); die();
                if ($menu_object->title == 'Log in') {
                    $current_user = wp_get_current_user();
                    $menu_object->title = $current_user->user_login . " - Log out";
                    $menu_object->url = wp_logout_url();;
                }
            }
        }
    return $sorted_menu_objects;
}

Found the basis for that here: Remove a menu item in menu

Obviously you need to change the line

if (is_user_logged_in()) {

to

if( isset($_SESSION['user']) ) {

and you may need to check for additional menu items to change their title and url depending on status (Logged in or out)

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

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