Last active
July 6, 2020 10:30
-
-
Save tillkruss/5268280 to your computer and use it in GitHub Desktop.
Disable WordPress front-end search functionality.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! is_admin() ) { | |
add_action( 'parse_query', function( $query ) { | |
if ( $query->is_search ) { | |
unset( $_GET['s'], $_POST['s'], $_REQUEST['s'] ); | |
$query->set( 's', '' ); | |
$query->is_search = false; | |
$query->set_404(); | |
header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' ); | |
} | |
}, 5); | |
} | |
add_action( 'widgets_init', function() { | |
unregister_widget( 'WP_Widget_Search' ); | |
}, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment