[Resolved] Search Box Clear

Home Forums Support [Resolved] Search Box Clear

Home Forums Support Search Box Clear

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #574585
    Daren

    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?

    #574769
    Tom
    Lead Developer
    Lead Developer

    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 ๐Ÿ™‚

    #575559
    Daren

    Seems to work fine, thanks.

    #575664
    Tom
    Lead Developer
    Lead Developer

    You’re welcome ๐Ÿ™‚

    #646191
    Daren

    How would I do this for the widget search?

    #646420
    Tom
    Lead Developer
    Lead Developer

    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=""

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.