Created
January 16, 2014 16:57
-
-
Save conor-egan/8458680 to your computer and use it in GitHub Desktop.
Prevent WordPress redirecting to homepage with empty search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Stop Empty Search Requests redirecting to homepage | |
*/ | |
//$_GET is an array of variables sent from the search form | |
//isset returns true if $_GET is not null | |
//empty returns true is $_GET is null | |
// function automatically populates the search $_GET request with an empty space | |
function jc_stop_search_redirect( $vars ) { | |
if( isset( $_GET['s'] ) && empty( $_GET['s'] ) ) | |
$vars['s'] = " "; | |
return $vars; | |
} | |
add_filter( 'request', 'jc_stop_search_redirect' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment