The tutorial shows you how to add a class and style it.
add_filter( 'wp_nav_menu_items','add_search_box', 10, 2 );
function add_search_box( $items, $args ) {
$items .= '<li class="your-class">' . get_search_form( 'echo=0' ) . '</li>';
return $items;
}
For CSS questions, please ask on Stackoverflow.
But the code doesn’t enable you to select between the primary or secondary nav menus unless you extend it like this.
add_filter( 'wp_nav_menu_items','wpsites_add_search_box', 10, 2 );
function wpsites_add_search_box( $items, $args ) {
if ( 'primary' != $args->theme_location )
return $items;
$items .= '<nav class="your-class">' . get_search_form( 'echo=0' ) . '</nav>';
return $items;
}
Written about this topic several times and i know you would want to use the same class as your themes nav menu if you want to style it the same.
Related Posts:
- Customizing Only a Specific Menu using the “wp_nav_menu_items” Hook?
- Custom search filter causes menu and query_posts problems
- How to use a WordPress’ existing admin icon?
- wp_nav_menu() not working on Custom Search Page
- Add custom SVG icons to Social Icon MENU in WordPress Twenty Seventeen Child Theme
- How to get Menu Navigation Labels to output HTML
- Where do custom menus get constructed?
- How to show Home Page link in WordPress Menu and how to add an icon to this?
- 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
- Get custom classes in WordPress Navigation Menu
- How to add search to menu?
- how to add home icon instead of text in wordpress menu
- Search form as list item in menu?
- Admin: WooCommerce Navigation Menus do not show empty categories search tab
- Where to place a svg chevron down in my custom walker?
- how to add fa fa icons customize menu using wp_nav_menu function?
- 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
- Icon not shown in Dropdown menus in Twenty Seventeen Theme
- How to change mobile menu (toggle) icon in WordPress – Full Site Editing?
- Why do Custom Nav Menus generate so many classes on list items? Can I manage this somehow?
- Add separator to admin submenu
- register_nav_menus() won’t register menus
- How do I add nested categories to drop-down menu in twenty-eleven?
- Add custom page link with anchor
- How to include the ‘current-menu-ancestor’ class on a custom post type menu in WordPress?
- HTML Bootstrap navigation menu to WordPress menu using wp_nav_menu
- List children of second level sub page
- Show top-level parent with submenu menu walker
- Add section to custom menu panel
- Adding a class (arrows) to main menu links that have children?
- How to change menu according to the language?
- Highlight the “Home” / “Blog” button while on main page
- Navigation (wp_nav_menu) refuses to nest within parent element
- how to add Custom menu item like User name in Header Menu only
- Display three different levels of navigation from wp_nav_menu separately?
- Wp_Nav_Menu – Identify the last menu item
- Add custom menu item metabox in Navigation Settings
- Menus – Open items in new tab/window?
- Image as a link using wp_nav_menu()
- Highlight another nav item
- Get category ID from nav menu
- How to make link to different categories that in them selves loads different menus?
- Programmatically add existing pages and subpages to Appearance Menu
- Highlight current post ancestor parent menu items
- Ad custom admin page like WordPress customizer [closed]
- Appearance Menus Screen – menu item drop down menu not functioning
- Weird behaviour on Edit Menus screen
- Remove nav menu item by script
- Make a navigation menu in the same post [duplicate]
- Custom Menu Broken WP 3.8.1 Update
- How to actually make menu walker alive on admin interface?
- Get menus created with menu editor?
- How to I know the class or ID of my theme?
- Highlight parent if item from submenu is active
- How to exclude pages in the menu without pageID?
- Missunderstanding of WordPress menus
- How to add schema.org SiteNavigationElement and property URL to navbar?
- changing host.. data loss
- Theme Location empty
- Replace the slug of parent pages with # [closed]
- How to buid wordpress menu with auto width sub-menu items in dropdown menu without any items sharing one line [closed]
- Page appears after de registering from menu
- If current menu item is child or parent with child?
- Is it possible to dynamically register menus?
- Dynamic menu wp_list_pages displaying only current branch including: current page, his siblings and its childs
- Parent Page > Child Page Menu
- Opening Menu link in another tab
- How to add class to anchor using wp_nav_menu
- displaying meta key value with wp_page_menu
- WordPress Menus – How to add inline styles to UL menus
- Is it possible to link to the same page from wordpress page menu?
- Remove current-menu-item for a specific link
- How to work with a custom theme that someone else created before me? (details below)
- changin the url (permalink as it goes these days) on one specific menu layer
- Custom menu items in admin
- WordPress database issues – menu not saving correctly, media thumbnails not showing
- WordPress Accessible Keyboard Menus
- Parent link need to go first child submenu
- mysterious menu
- Importing large product categories into wordpress menu
- Different HTML markup for similar menus
- Menu for specific user
- All custom links suddenly lack href attributes
- wp_nav_menu custom Page class
- Why does appear? I’m trying to remove a generic link called navigation on my main menu
- WordPress – Apperance > Menu
- How to stop showing menu in static home page
- How do I fix the URL used in the WordPress admin menu for customize.php
- Menu id in nav menu ignored
- How do I add a link to the menu that has a charector (?) in it?
- Problem with custom menus
- Custom Class to wp nav menu
- Second tier sidebar navigation
- Problem to asign class to with wp_nav_menu()
- Site with all content on the front page
- Why is my hamburger menu not shown? [closed]
- Database structure Menu Item