Using a menu walker add a custom item at the end of the menu’s items. You don’t need a walker in this case. A filter called wp_nav_menu_items
is available. It allows you to edit the list items of a menu. Just append your own list item with search field.
1 2 3 4 5 6 7 | add_filter( 'wp_nav_menu_items', 'add_search_to_nav', 10, 2 ); function add_search_to_nav( $items, $args ) { $items .= '<li>SEARCH</li>'; return $items; } |
Note: if you only want to target a specific menu, a dynamic filter exists:
1 | wp_nav_menu_{$menu->slug}_items |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.