
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;"));
}
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.
I was just thinking about disable the WP search on my blog! Thanks for this useful tip
No problem, hope you find it useful
This is my first time come here,I really love the theme you are using
Thank you for your kind words
Interesting post but not entirely sure why you would want to do something like this? If you want to disable search on your site then don’t include a search box in your theme.
That is the obvious thing to do, but that just removes the search box rather than disable the search function itself.
Even without a search box you can still search by using: http://yoursite.com/?s=search-term
Which some users do not want their readers to do for whatever reason.
Cheers for your comment
will try it out for sure
If anyone is looking for an advanced search tool including searching other websites as part of your search. Try SearchBlox for WordPress http://www.searchblox.com/searchblox-wordpress-plugin-now-available
Trackbacks