Skip to content

Instantly share code, notes, and snippets.

@premanshup
Created August 27, 2019 12:46
Show Gist options
  • Save premanshup/0336321556c498c3c950c0318e937d28 to your computer and use it in GitHub Desktop.
Save premanshup/0336321556c498c3c950c0318e937d28 to your computer and use it in GitHub Desktop.
/**
* Display search form.
*
* @param bool $echo Default to echo and not return the form.
* @return string|void String when $echo is false.
*/
function astra_get_search_form( $echo = true ) {
$form = '<form role="search" method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
<label>
<span class="screen-reader-text">' . _x( 'Search for:', 'label', 'astra' ) . '</span>
<input type="search" class="search-field" ' . apply_filters( 'astra_search_field_toggle_data_attrs', '' ) . ' placeholder="' . esc_attr_x( 'My Placeholder', 'placeholder', 'astra' ) . '" value="' . get_search_query() . '" name="s" role="search" tabindex="-1"/>
</label>
<button type="submit" class="search-submit" value="' . esc_attr__( 'Search', 'astra' ) . '"><i class="astra-search-icon"></i></button>
</form>';
// Replace My Placeholder with your desired string.
/**
* Filters the HTML output of the search form.
*
* @param string $form The search form HTML output.
*/
$result = apply_filters( 'astra_get_search_form', $form );
if ( null === $result ) {
$result = $form;
}
if ( $echo ) {
echo $result;
} else {
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment