Skip to content

Instantly share code, notes, and snippets.

@tillkruss
Last active July 6, 2020 10:30
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tillkruss/5268280 to your computer and use it in GitHub Desktop.
Disable WordPress front-end search functionality.
<?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