Tagged: javascript, search
I’ve placed a search bar in the header area of the site and have disabled the ajax results using css. All is working well. However, whenever I search for something using the search box, the search term remains in the form field instead of the ‘Search’ placeholder text.
To clarify, on page load, the search box has the placeholder text ‘Search’. I search for the term ‘sofa’ and hit return. Search result page displays correctly, but now the search box in the top of the page says ‘sofa’ instead of ‘Search’. It’s also live text, not placeholder.
Shouldn’t this be clearing out on page load?
Hey David,
Thank you for contacting us.
Would you mind providing a precise link to the page, showing the elements in question? We need to be able to inspect them in order to help :)
Best regards,
Vinay
Attaching site url in private content. Thanks for the help.
Checking in. Were you able to recreate the issue with the info provided?
Hi,
Please try adding this at the very end of your themes/child theme’s functions.php file:
// Reset search field
function searchPlaceholder(){
?>
<script>
jQuery(document).ready(function() {
jQuery('#header #searchform').find("input[type=text]").val(" ");
});
</script>
<?php
}
add_action('wp_footer', 'searchPlaceholder');
// End function
For more information about adding custom script please check this link.
Best regards,
Vinay
This works for me.
Many thanks for the help.
Hi,
I’m glad this was resolved. If you need additional help, please let us know here in the forums.
Best regards,
Jordan Shannon