raunak-gupta
10/8/2016 - 9:38 AM

Add Search Form To A WordPress Menu

Add Search Form To A WordPress Menu

<?php

//Add Search Form To A WordPress Menu
add_filter('wp_nav_menu_items', 'add_search_form', 10, 2);

 function add_search_form($items, $args) {
          if( $args->theme_location == 'CHANGE-THIS-TO-YOUR-MENU-NAME' )
          $items .= '<li class="search">
                      <form role="search" method="get" id="searchform" action="'.home_url( '/' ).'">
                        <input type="text" value="search" name="s" id="s" />
                        <input type="submit" id="searchsubmit" value="'. __('Search') .'" />
                      </form>
                    </li>';
     return $items;
}