Are you looking for a way to totally disable search functionality on your website? While there’s probably a plugin for this, we have created a quick code snippet that you can use to completely disable public search in WordPress.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
function example_disable_public_search( $q ) { if ( $q->is_admin ) { return $q; } if ( $q->is_search ) { unset( $_GET['s'] ); unset( $_POST['s'] ); unset( $_REQUEST['s'] ); $q->set( 's', '' ); $q->is_search = false; $q->set_404(); } } add_action( 'parse_query', 'example_disable_public_search', 5 );
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 7 best WordPress poll plugins and how to fix the error establishing a database connection in WordPress.
Comments Leave a Reply