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]
- Display a portion/ branch of the menu tree using wp_nav_menu()
- Display only page specific sub menu items using Custom Walker
- non-clickable placeholder in the menu
- Menu is not visible in appearance
- Ways to give a wp_list_pages menu link specific class names?
- I want remove last after wp_nav_menu
- Organizing by super-categories (or nested categories)?
- Adding first and last class to Menu on top level only
- wp_list_pages – show pages immediately 1 level below current level
- Add within the output of
- How do I get my wp_nav_menu single category page to highlight the parent?
- Where to update the Static Pages Blacklist for Multisite Install?
- Vertical Sidebar Menu Parent and Child not displaying correctly [closed]
- Hide Menu items base on capability
- How to show Home Page link in WordPress Menu and how to add an icon to this?
- How to add custom menu item on plugin activation?
- Outside the loop, how can I echo the current page’s menu title?
- Use menu class in walker function
- Menu link to all posts (all categories included)
- How do you return a menu with the menu name?
- You do not have permission to create Navigation Menus – Twenty Twenty-Two theme
- Walker class conditional based on parent menu item label or custom css class
- SlickNav – Google Lighthouse Accessibility issue for collapsed menu button
- Creating a navigation menu to see where you are on your website
- Custom format nav menu only using div and a
- ‘wp_get_nav_menu_items’, when fired inside of the ‘wp_update_nav_menu’ hook, returns old menu items, instead of new
- Menu custom link not working for external site
- Sticky Header in WordPress using BootstrapWP theme [closed]
- Walker Class – Check if menu item has description and if so add class to li
- Multiple languages menus problem
- Switch from hover to click on Twenty Twelve Menu
- How can I switch pages?
- How to override menu markup?
- How to remove dropdown from wp_nav_menu
- Automatically Display Sub Menu
- Recent Posts widget missing current_menu_item class
- WordPress custom Nav Walker
- In admin edit-menu screen, newly added menu items always go to the bottom of the list
- Static site menu with multiple ul’s to wp menu
- How can I make wp_nav_menu() support tags?
- active menu in post page
- WP nav menu + Bootstrap, add role=”menu” to UL
- Display pictures instead of text in menus
- how to check if given page is active page
- how to set the link in wordpress such that on clicking it doesn’t open another page but go to the bottom of same page
- custom walker class for own menu?
- WordPress Menu – creating a fake link [closed]
- Add a menu metabox to post edit page
- Setting or plugin for showing submenus horizontally under the main menu, and keep them after selection
- New wp menu menu styling
- (Mobile) Hamburger menu disappeared from a page (only one)
- Add div content to my already existing menu
- Hiding menu on specific pages
- Bootstrap Menu bar shows up a toggle in Desktop Mode
- For a menu custom link (without a link) a “#” is appended. Can this just be blank, i.e. NO link?
- sidebar navigation problem with child pages not all display.?
- How to point menu to my homepage
- save_post() on Menu Save
- dot.com/car1 does work, but dot.com/transport/car1 doesn’t work
- code to add an extra selection to the menu editor
- update_post_meta breaking wp_update_nav_menu_item
- Menu dropdown disapears behind slider
- Building a menu from a large number of pages?
- Cannot add home page url to menu with #
- Accidental reverse order of menu items in one menu
- Extend Individual Menu on Page Function to individual Submenue on Page Function?
- How do I remove a menu from a theme?
- Access CSS Classes specified in Menu options
- How to output the menue structured for tabbed navigation?
- Walker for menus
- Custom Menu based off custom header
- How to add an tag when a menu item is a dropdown(or has a sub-menu) [duplicate]
- Remove “Next Post” in nav_menu
- Adding an additional menu in WordPress
- Making current_page_item work with wp_list_pages in sidebar on post pages
- Menu not Showing on Mobile or While the page is shrinked
- My Menu Disappears on my Custom Link Homepage on Mobile
- How to centre menu items on horizontal nav bar? (e.g. make margins equal) [closed]
- Add A Menu Item To A WP_Nav_Menu Navigation via PHP Function
- Active Navigation Class Based on URL on icon
- Changing login url
- Rename Menu icon in Twenty seventeen theme
- WordPress Menu – Adding a new dynamic element to the menu
- One item on menu is not clickable when it should be