[Resolved] Automatically Clearing the Search in Navigation

Home Forums Support Automatically Clearing the Search in Navigation

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #936410
    Janet Davis

    Hello,

    After someone uses the search I’d like the search to clear. It doesn’t clear in the navigation search, and when nothing is found the same search is in the search on the nothing found page.

    I found the following which I put into Snippet plugin – but it didn’t work.
    Thank you
    Jan

    add_filter( ‘generate_navigation_search_output’, function() {
    return sprintf( // WPCS: XSS ok, sanitization ok.
    ‘<form method=”get” class=”search-form navigation-search” action=”%1$s”>
    <input placeholder=”Type to search” autocomplete=”off” type=”search” class=”search-field” value=”” name=”s” title=”%2$s” />
    </form>’,
    esc_url( home_url( ‘/’ ) ),
    esc_attr_x( ‘Search’, ‘label’, ‘generatepress’ )
    );
    } );

    #936428
    Leo
    Staff
    Customer Support
    #936720
    Janet Davis

    Hi Leo,
    I put the coding (see the bottom – copy paste from your post) into snippet plug-in hit saved.
    Doesn’t work.

    I created a new snippet and saved. Doesn’t work.
    I made sure the snippet was on. Doesn’t work.

    Thank you
    Jan

    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’ )
    );
    }

    #937153
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    I’m not seeing the navigation search on your website – did you turn it off?

    Let me know πŸ™‚

    #937173
    Janet Davis

    Hey Tom,
    My apologies, when I went to the library starter of Wordsmith I didn’t turn it back on.
    It’s on now and it has the same issue.

    Thank you
    Jan

    #937204
    Leo
    Staff
    Customer Support

    Are you already using the generate_navigation_search_output filter in another function?

    #937284
    Janet Davis

    Not that I know of.
    I didn’t create anything

    #937298
    Leo
    Staff
    Customer Support

    I see Enter your search placeholder text when activating the search.

    I believe that’s added with the same filter?

    #937311
    Janet Davis

    Below is what is in the css and the snippet

    This is what is in the CSS
    input::placeholder {
    line-height: 1;
    }

    .main-navigation li.search-item {
    display: inline-flex !important;
    align-items: center;
    }
    .main-navigation li.search-item:before {
    content: ‘Search Site’;
    margin-right: 10px;

    }

    .navigation-search input[type=”search”],
    .navigation-search input[type=”search”]:active,
    .navigation-search input[type=”search”]:focus {
    color: #000000;
    background-color: #ffffff;
    }

    input::placeholder {
    line-height: 1;
    color: #000000;
    }

    This is what is in the snippet

    add_filter( ‘generate_navigation_search_output’, function() {
    printf(
    ‘<form method=”get” class=”search-form navigation-search” action=”%1$s”>
    <input type=”search” placeholder=”Enter your search” class=”search-field” value=”%2$s” name=”s” title=”%3$s” />
    </form>’,
    esc_url( home_url( ‘/’ ) ),
    esc_attr( get_search_query() ),
    esc_attr_x( ‘Search’, ‘label’, ‘generatepress’ )
    );
    } );

    #937336
    Leo
    Staff
    Customer Support

    Change the PHP snippet to this one ONLY:

    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" placeholder="Enter your search" class="search-field" value="" name="s" title="%2$s" />
    		</form>',
    		esc_url( home_url( '/' ) ),
    		esc_attr_x( 'Search', 'label', 'generatepress' )
    	);
    }
    #937469
    Janet Davis

    I put that into my snippet.

    What I wrote that was in my css was in the site css.

    I am still not getting it to clear.

    Thank you

    #937473
    Leo
    Staff
    Customer Support

    Did you remove the other functions that were added?

    #937477
    Janet Davis

    These are the only 2 snippets I have in the snippet plugin
    for the place holder

    add_filter( ‘generate_navigation_search_output’, function() {
    printf(
    ‘<form method=”get” class=”search-form navigation-search” action=”%1$s”>
    <input type=”search” placeholder=”Enter your search” class=”search-field” value=”%2$s” name=”s” title=”%3$s” />
    </form>’,
    esc_url( home_url( ‘/’ ) ),
    esc_attr( get_search_query() ),
    esc_attr_x( ‘Search’, ‘label’, ‘generatepress’ )
    );
    } );

    and to clear

    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” placeholder=”Enter your search” class=”search-field” value=”” name=”s” title=”%2$s” />
    </form>’,
    esc_url( home_url( ‘/’ ) ),
    esc_attr_x( ‘Search’, ‘label’, ‘generatepress’ )
    );
    }

    #937480
    Leo
    Staff
    Customer Support

    That’s what I’m trying to say.

    I’ve combined the placeholder and clear function in the snippet above so please only use that one and remove the others:
    https://generatepress.com/forums/topic/automatically-clearing-the-search-in-navigation/#post-937336

    Let me know if this is clear πŸ™‚

    #937485
    Janet Davis

    Ahh that makes sense now.
    And yes it works now thank you.

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