If the goal is to simply redirect to the 404 php when searching. This solution works with less code.
Also, this solution will make sure the search query URL params "domain.com/?=furniture" is removed from address bar when the page reloads (vs. the other approaches which still show the search query URL params).
/** Remove the search capability by redirecting all search queries to the 404 page, in the "functions.php" file **/
function redirect_search_to_404_page( ) {
if ( is_search() && !is_admin() ) {
wp_redirect( '/404' );
exit;
}
}
add_action( 'wp_footer', 'redirect_search_to_404_page' );