Skip to content

Instantly share code, notes, and snippets.

@terrytsang
Created September 11, 2022 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terrytsang/d27c86da844fa7929c1f40ecd44888be to your computer and use it in GitHub Desktop.
Save terrytsang/d27c86da844fa7929c1f40ecd44888be to your computer and use it in GitHub Desktop.
Disable WordPress search function
<?php
//add this code into functions.php to disable search
function tt_filter_query( $query, $error = true ) {
if ( is_search() & !is_admin()) {
$query->is_search = false;
$query->query_vars['s'] = false;
$query->query['s'] = false;
// to error
if ( $error == true )
$query->is_404 = true;
}
}
add_action( 'parse_query', 'tt_filter_query' );
add_filter( 'get_search_form', function($a) {return null;});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment