How to disable the WordPress search functionality

Add this snippet to your (child-)themes functions.php to disable the search widget and redirect any search query to 404.