Archived topic
Search Box Clear
5 replies · Started by Daren on May 13, 2018
I am using the navigation search, after entering a term to search for the input retains the last search text unless you hit the x to clear it. Is there a way to always auto clear the input after each search so users don't manually have to themselves?
Hi there,
Give this function a shot:
add_filter( 'generate_navigation_search_output', 'tu_remove_search_query' );
function tu_remove_search_query() {
printf( // WPCS: XSS ok, sanitization ok.
'<form method="get" class="search-form navigation-search" action="%1$s">
<input type="search" class="search-field" value="" name="s" title="%2$s" />
</form>',
esc_url( home_url( '/' ) ),
esc_attr_x( 'Search', 'label', 'generatepress' )
);
}
Let me know :)
Seems to work fine, thanks.
You're welcome :)
How would I do this for the widget search?
You would need to copy the searchform.php file into your child theme: https://github.com/tomusborne/generatepress/blob/2.1.3/searchform.php
Then on line 15, replace this:
value="<?php echo esc_attr( get_search_query() ); ?>"
With this:
value=""