Site logo

Archived topic

Search Box Clear

5 replies · Started by Daren on May 13, 2018

Viewing posts 1–6 of 6

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?

This archived topic is closed to new replies.