The following column WordPress Tutorial will introduce how to disable the WordPress front-end search function. I hope it will be helpful to friends in need!
#The search function that comes with WordPress is very weak and very inefficient. If someone takes advantage of this flaw to initiate many search requests, your server is likely to go down. We can use Baidu, 360, etc. to implement on-site search, and prohibit the front desk from using the search function that comes with WordPress. Just add the following code to the functions.php file of the current theme.
Code
//禁用WordPress前台搜索功能 function disable_search( $query, $error = true ) { if (is_search() && !is_admin()) { $query->is_search = false; $query->query_vars['s'] = false; $query->query['s'] = false; if ( $error == true ) // 执行搜索后显示的错误页面 // $query->is_home = true; //跳转到首页 $query->is_404 = true;//跳转到404页 } } add_action( 'parse_query', 'disable_search' ); add_filter( 'get_search_form', create_function( '$a', "return null;" ) );
Note:
You can choose the error page displayed after performing the search, which is to jump to 404 or the homepage of the website.
The original code comes from the Internet and does not support PHP7.2. It has been modified to support higher versions of PHP.
The above is the detailed content of How to disable WordPress front-end search functionality. For more information, please follow other related articles on the PHP Chinese website!