If your website doesn’t use the built-in WordPress search feature, you can disable it and redirect search requests to the homepage.
Steps
- Open your WordPress theme
functions.phpfile. - Add the code below at the end of the file.
- Save the file.
- Test by visiting a search URL such as
?s=test.
Done — visitors will be redirected to the homepage instead of viewing search results.
function disable_wp_search() {
if (is_search()) {
wp_redirect(home_url());
exit;
}
}
add_action('template_redirect', 'disable_wp_search');