Disable WordPress Search

Snippets | By | 16 December 2010 | Comments 7

For whatever reason the time may come when you need to disable WordPress’ in built search function, your project might not call for it or you might want to change it out for Google Search for example.

To do this is relatively easy, backup for functions.php file before you tinker, then add the following:

function no_search_please($query, $error = true) {

if (is_search()) {
$query->is_search = false;
$query->query_vars[s] = false;
$query->query[s] = false;

if ($error == true)
$query->is_404 = true;
}
}
if (!is_admin()) {
add_action('parse_query', 'no_search_please');
add_filter('get_search_form', create_function('$a', "return null;"));
}

Conclusion

And that is about it, your WordPress install now has no search function and even if someone tries to search in the address bar (eg: http://yoursite.com/?s=search-term) they will get a 404 error page.

Paul Maloney is a UK based web designer/developer and runs the design agency Tropica. He particularly enjoys using and working with WordPress and has a keen interest in typography. You can also follow Paul on Twitter.

Visit Paul Maloney's website

7 Comments

  • December 16, 2010
    • December 16, 2010
  • December 17, 2010
    • December 17, 2010
  • December 19, 2010
    • December 19, 2010
  • January 1, 2011

Leave A Comment.