- This topic has 15 replies, 3 voices, and was last updated 1 year, 7 months ago by
Leo.
-
AuthorPosts
-
June 20, 2019 at 5:24 pm #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
Janadd_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’ )
);
} );June 20, 2019 at 6:15 pm #936428Leo
StaffCustomer SupportHi there,
Can you try this code?
https://generatepress.com/forums/topic/search-box-clear/#post-574769It was recently tested to be working:
https://generatepress.com/forums/topic/search-nav-color/#post-926121Let me know π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/June 21, 2019 at 3:14 am #936720Janet 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
Janadd_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’ )
);
}June 21, 2019 at 8:48 am #937153Tom
Lead DeveloperLead DeveloperHi there,
I’m not seeing the navigation search on your website – did you turn it off?
Let me know π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJune 21, 2019 at 8:59 am #937173Janet 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
JanJune 21, 2019 at 9:24 am #937204Leo
StaffCustomer SupportAre you already using the
generate_navigation_search_output
filter in another function?Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/June 21, 2019 at 10:53 am #937284Janet Davis
Not that I know of.
I didn’t create anythingJune 21, 2019 at 11:13 am #937298Leo
StaffCustomer SupportI see Enter your search placeholder text when activating the search.
I believe that’s added with the same filter?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/June 21, 2019 at 11:26 am #937311Janet 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’ )
);
} );June 21, 2019 at 11:51 am #937336Leo
StaffCustomer SupportChange 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' ) ); }
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/June 21, 2019 at 3:32 pm #937469Janet 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
June 21, 2019 at 3:33 pm #937473Leo
StaffCustomer SupportDid you remove the other functions that were added?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/June 21, 2019 at 3:39 pm #937477Janet Davis
These are the only 2 snippets I have in the snippet plugin
for the place holderadd_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’ )
);
}June 21, 2019 at 3:44 pm #937480Leo
StaffCustomer SupportThat’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-937336Let me know if this is clear π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/June 21, 2019 at 3:52 pm #937485Janet Davis
Ahh that makes sense now.
And yes it works now thank you. -
AuthorPosts
- You must be logged in to reply to this topic.