I am wanting to use a search form in more than one place on the page (wordpress site) however, there seems to be issues (clashing ids I presume) when I use get_search_form() more than once. I have modified the following code in searchform.php so that the id is updated each time however, there still seems to be issues. In addition, creating another search form and function also runs into similar issues. Is there something I am missing? thanks!
function wpdocs_my_search_form( $form ) {
static $form_index = 0;
$form_index++;
$form = '<div class="form-container">
<form role="search" method="get" id="searchform-' . $form_index . '" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
<div class="search-container">
<input type="text" value="' . get_search_query() . '" name="s" id="s-' . $form_index . '" />
<input type="submit" value="' . esc_attr__( 'Search' ) . '" />
</div>
</form>
</div>';
return $form;
}
add_filter( 'get_search_form', 'wpdocs_my_search_form' );