To only add the custom search box to the main menu you could pass the second parameter provided by the wp_nav_menu_items filter and check if the theme_location is the primary location
add_filter('wp_nav_menu_items','search_box_function', 10, 2);
function search_box_function( $nav, $args ) {
if( $args->theme_location == 'primary' )
return $nav."<li class="menu-header-search"><form action='http://example.com/' id='searchform' method='get'><input type="text" name="s" id='s' placeholder="Search"></form></li>";
return $nav;
}
Related Posts:
- Custom search filter causes menu and query_posts problems
- wp_nav_menu() not working on Custom Search Page
- Where do custom menus get constructed?
- Create search form in menu as in Twenty Fourteen theme
- get_search_form() doesn’t appear to take parameter into account
- Custom Links menu items include in Search Results
- How to add search to menu?
- Search form as list item in menu?
- Admin: WooCommerce Navigation Menus do not show empty categories search tab
- How To Add Class To Style Search Box
- After WordPress 4.8 upgrade, wp_nav_menu() string search / replace not working
- Hiding Widget On Mobile Devices Removes Our Product Search Box On Mobiles
- Unregister Nav Menu from Child-Theme
- Deleted pages are NOT removed from custom menus?
- Keeping parent menu items active in child pages
- Add Page ID class to nav menu items
- Way to bulk delete menu items in new 3.x Appearance > Menus system?
- Pass a parameter to a menu walker
- Menu is not visible in appearance
- WordPress nav_menu_link_attributes Not Working
- Customize the menu by adding items
- Organizing by super-categories (or nested categories)?
- Adding first and last class to Menu on top level only
- wp_nav_menu log in/out link?
- How do I get my wp_nav_menu single category page to highlight the parent?
- Accesibility problems with dropdown menus in twentyten theme or others
- Theme menu in Admin Panel
- How to target children of child pages
- How to insert custom code into wp_nav_menu structure?
- How to add custom menu item on plugin activation?
- Outside the loop, how can I echo the current page’s menu title?
- WordPress Admin Bar Covering & Overlapping Fixed Menu Header [closed]
- Input type search in Menu
- getting parent page id when using custom menu.
- Use menu class in walker function
- Menu link to all posts (all categories included)
- Change name & menu_name for Profile in the default menu, w/o altering core files?
- wp-menu ‘automatically add custom taxonomy terms’ like it does for pages? [closed]
- SlickNav – Google Lighthouse Accessibility issue for collapsed menu button
- Creating a navigation menu to see where you are on your website
- How I can overlap my menu in my header picture
- current-menu-item class in CSS
- Put class on instead li
- Tiles as a navigation
- Custom format nav menu only using div and a
- How to make the Primary Menu stay the same in the PC and mobile versions of the Twenty Sixteen theme
- How to add notifcations to front-end menu for users when they recieved replies?
- Page content loading issue using Walker_Nav_Menu
- Links do not open from click, only in new tab [closed]
- Default menu editor with automatic page list
- Switch from hover to click on Twenty Twelve Menu
- Can I have custom post types in “Add menu items” on in the Admin > Appearance > Menu
- Add a custom class to nav li item
- Adding anchors in WordPress Menus
- Automatically Display Sub Menu
- Adding a unique ID to each sub-menu
- How to add css to single navigation text? [closed]
- WordPress custom Nav Walker
- My navigation menu isn’t working. What happened? Please help!
- How to get a multidimensional array of my menu?
- How to get the name of the homepage’s menu?
- How to get submenu of admin menu?
- wp_nav_menu without menu or theme_location specified
- active menu in post page
- What is the $menu parameter used of in wp_nav_menu()?
- Blending Foundation’s Tabs with WordPress Nav Menu & Display Active Tab
- Show wp_nav_menu() based on URL with no fallback
- Editing the nav menu?
- How to display conditional menus with Twenty-twenty two theme (and other new block themes)?
- Keep source page URL parameters on custom link menu item
- I’m trying to remove a duplicate menu, which only appears on the homepage?
- Embedding an external webpage within a page? Is it possible, is it a good idea?
- How to remove empty line space in navigation menu?
- Is it possible to get_the_post_thumbnail (Featured Image) inside a sprintf function?
- WP Menu editor is hiding options for menu items
- Assign a different menu depending on custom taxonomy
- Homepage Menu Link Won’t Function
- Appearance -> Menu editor completely unresponsive
- Custom menu is rendered in all menus
- javascript i wrote not working, can’t figure out why [closed]
- Making my main menu a hamburger menu on all platforms
- menu change after theme change
- Appearance –> Menu -not showing on my main page
- how to create pages and link them to a menu
- menu mobile show up even i in desktop mode in Newspaper Theme
- WordPress fountainpress header is covering top bar
- Outputting Page Title As Tooltip
- Current menu item class issue
- How to add class and span to
- Appearance > Menus
- extra tag is added in wp_nav_menu
- menu item active class for author.php
- My WordPress menu based on Twitter bootstrap creates menu-item and not page-item
- menu entries are lost
- menu items toggle and display on screen size reduction
- How to get wordpress navigation to work
- How do I show a different secondary navigation menu for each section of my website?
- How to center top Menu bar [closed]
- Changing when mobile menu is displayed
- Navigation menu displays permalinks