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:
- Add a logout menu link [duplicate]
- add the user name to menu when user is logged in [closed]
- wp_nav_menu log in/out link?
- How to Show Different Menus to Logged in Users in WordPress [duplicate]
- login logout menu changes in wordpress [closed]
- How to add Loginout to Sub-menu
- How to make Logout Link consistently appear on all web pages?
- Add “Logout” link to navigation menu
- Add log in link to menu in Twenty Twelve
- Making WordPress’ page and menus visible only for logged in users, checking session variables
- Show menu item only if user is logged In (not word press login)
- do_action appearing outside of menu?
- Use wp_logout_url() in menu creation page
- Use another menu when logged in
- Change “login/register” to “useraccount” when a user has logged in
- To Add Logout Button in Menu [duplicate]
- Retrieving a list of menu items in an array
- Error: Declaration of MyClass::start_lvl() should be compatible with that of Walker_Nav_Menu::start_lvl()
- Using nonce in menu item
- Filter out built-in wp_nav_menu classes but keep custom class
- remove last separator?
- How to get a different mobile menu than desktop menu in the twentytwelve child theme
- WordPress built in breadcrumb trail menu?
- Custom Nav Walker menu – Display children count
- WordPress Export Import Site Navigation Menu
- Bar separated navigation by extending Walker_Nav_Menu
- WordPress Menu Disappears when $query->query_vars[‘meta_key’] is set
- how do I delete (not exclude) a menu item from navigation bar
- show only a given level in nav menu
- Custom menus created but does not show up in admin panel
- Replace menu tag with tag
- How to display custom post meta in the appearance->menus page
- Anchor only wp_nav_menu
- wp_nav_menu custom walker – child items
- Where do custom menus get constructed?
- How to remove div container in custom menu?
- Keeping ‘current-menu-item’ highlight of navigation menu?
- Does loading of sub pages in menu cause load to the server?
- Get admin menu link
- Possible to add a dynamic link to a sub-menu via wp_nav_menu_items?
- How can I access the menu ID of an element in a WordPress Nav_Walker
- Fragment URL in navigation item without a custom link
- How to translate menu items?
- Unable to create or edit menus
- How to Implement Submenu Using wp_nav_menu
- Close dropdown menu on click or scroll outside the menu [closed]
- How to have the Header show different content on different pages?
- WordPress menu not loading in the admin side appearence-> menu tab
- Is there no straightforward way to display a separate second level using wp_nav_menu()?
- CSS_Menu_Walker not showing on mobile view?
- HTML list menu to WordPress menu
- Filter Menu Items by Custom User Role in a page
- Add “drop-down arrow” for menu items with sub-menus
- Cannot seem to replace the native menu with the menu I created, so 2 menus appear
- Add span in top menu item with nested itens
- Secondary Navigation Menudisappeared When using wp_nav_menu_items
- Add Labels to Admin Menu ( How To )
- How to remove ‘wordpress…’ text from page titles in tabs
- Hide a menu on posts
- WP navigation list classes
- Can’t create a SubMenu
- unable to add custom page/tab to my account woocommerce
- Add Login/Logout Menu Item to Primary Nav “My Account” Submenu [Woocommerce] [closed]
- Add (grand)child pages automatically to nav menu
- Having trouble adding CSS class through menu to link
- Switch an entire nav menu if user is logged in
- Pull Menu Items Into an HTML element
- How to pass menu slug as a variable to wp_nav_menu?
- Add a string after each item in WordPress sub menu
- Add # to submenu URLs automatically
- Automatically Generated Menu pages
- Costum walker with sub menu item count
- Unable to nest categories in menu
- adding pages in underscores.me theme
- Trying to add Newline in Menu item
- How to unlock menu editing
- Can I now add a class in the anchor of my menu item with WordPress 5.4?
- How to add a taxonomy type in Menus?
- Header Navmenu glitching in Chrome (but not other browsers)
- how to display different menu according to postid?
- Homepage is not loading
- Disable Mobile Menu, (always show desktop menu)
- Put two menus in the same location
- Add Featured Image and Title to wp_nav_menu items
- Secondary Menu display Primary Menu
- Is it possible to separate all submenu items?
- Frontside menu based on custom roles logged in permission
- Reveal hidden submenus on page load – Twenty Fifteen theme
- Admin Custom Menu Editor Disappeared
- Hide menu theme location for certain capabilities?
- Making a Custom Menu Sidebar Icon show as Current in css [closed]
- Adding two submenus to a menu
- Change archive link to single post
- Remove from wp_nav_menu() wordpress
- collapse twenty twelve submenu in mobile version
- Styling Active Links Within WordPress
- Make title bar collapse when scrolling
- Problem with float:left – unexpected behavior [closed]
- Twenty-Twenty-Two Child Theme Mega Menu
- 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?