Skip to content

Instantly share code, notes, and snippets.

@craigpearson
Created February 7, 2014 10:00
Show Gist options
  • Save craigpearson/8860034 to your computer and use it in GitHub Desktop.
Save craigpearson/8860034 to your computer and use it in GitHub Desktop.
Roots nice search redirect - fix
function roots_nice_search_redirect() {
$valued = $_GET["post_type"];
if(!empty($valued)) { $valued = "?post_type=".$valued; };
if (is_search() && strpos($_SERVER['REQUEST_URI'], '/wp-admin/') === false && strpos($_SERVER['REQUEST_URI'], '/search/') === false) {
wp_redirect(home_url('/search/'.str_replace(array(' ','%20'),array('+', '+'),urlencode(get_query_var('s'))).$valued), 301);
exit();
}
}
add_action('template_redirect', 'roots_nice_search_redirect');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment