How to Disable Empty Search Requests

Currently WordPress doesn’t include an option to disable the empty search queries, however, you can disable the ability to submit an empty search fields in WordPress by adding this code snippet into Theme options > Layout > Advanced > Custom JS (in footer):

$('input[type="search"').attr('required', 'required');

And if you want to customize WordPress to disable any empty search request and redirect them to the homepage you can add this code snippet into functions.php file inside your child theme:

function search_redirect($query) {
if ( !is_admin() && $query->is_main_query() ){
if ($query->is_search) { wp_redirect( home_url() ); exit; }
}
}
add_action('pre_get_posts','search_redirect');
pixfort
pixfort
Support Team

Hey, this is pixfort support team, if you still need help you can always reach us via your pixfort account

Related Posts

Search

Start typing to search for a specific article on our website

Made with Popup Builder
Image link
Hey there

Search for a specific article

Get started

Check useful guides to get started

Still need Help?

Send us a support message

Our usual reply time: 1 Business day