Home > CMS Tutorial > WordPress > How to disable WordPress front-end search functionality

How to disable WordPress front-end search functionality

藏色散人
Release: 2019-11-14 13:32:33
Original
2859 people have browsed it

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!

How to disable WordPress front-end search functionality

#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;" ) );
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template