Empty search shows home page on wordpress

OK, so you have a site. It’s not set up like a blog, so you don’t have a blog or posts page.

You notice that submitting the search form with nothing in it sends you to a broken home page.

There are all sorts of madnesses touted to fix this involving modifying the core wordpress code, which is a terrible idea given how often it updates.

stick this in your functions and ¡presto pronto! all better. This will just send you to your search page and show everything with a space in it..

add_filter( 'request', 'my_request_filter' );
function my_request_filter( $query_vars ) {
if( isset( $_GET['s'] ) && empty( $_GET['s'] ) ) {
$query_vars['s'] = " ";
}
return $query_vars;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.