如何在WordPress中禁用搜索功能

Do you want to disable the search feature in WordPress? Sometimes your site may not need the search feature and the search form in your theme may interfere with user experience. In this article, we will show you how to easily disable the search feature in WordPress.

您要禁用WordPress中的搜索功能吗? 有时,您的站点可能不需要搜索功能,主题中的搜索表单可能会干扰用户体验。 在本文中,我们将向您展示如何轻松禁用WordPress中的搜索功能。

Disabling search feature in WordPress
为什么以及谁应该禁用WordPress中的搜索功能? (Why and Who Should Disable Search Feature in WordPress?)

Many WordPress websites are simple business websites with a few pages. There is also a growing trend of one-page websites with vertical navigation.

许多WordPress网站是具有几页的简单商务网站 。 具有垂直导航的单页网站也有增长的趋势。

These websites does not have much content which makes search form a novelty item and not a useful feature.

这些网站内容不多,使得搜索成为一个新颖的项目,而不是有用的功能。

It also gives users the impression that there might be some other information that they can’t see and hence the search option. Removing search feature will clean up your website and offer a better user experience.

它还给用户留下了可能还有其他一些看不见的信息,因此还有搜索选项。 删除搜索功能将清理您的网站并提供更好的用户体验。

That being said, let’s take a look at how to easily remove search feature from your WordPress site.

话虽如此,让我们看一下如何轻松地从WordPress网站中删除搜索功能。

方法1.使用插件删除WordPress中的搜索功能 (Method 1. Remove Search Feature in WordPress Using a Plugin)

This method is easier and is recommended for all users.

此方法更简单,建议所有用户使用。

First thing you need to do is install and activate the Disable Search plugin. For more details, see our step by step guide on how to install a WordPress plugin.

您需要做的第一件事是安装并激活“ 禁用搜索”插件。 有关更多详细信息,请参阅有关如何安装WordPress插件的分步指南。

The plugin works out of the box, and there are no settings for you to configure.

该插件可以直接使用,没有可供您配置的设置。

Upon activation, it will remove search form from your WordPress theme and disable the search widget. If a user directly tried to enter a search query URL, the plugin will return a 404 error page.

激活后,它将从您的WordPress主题中删除搜索表单,并禁用搜索小部件。 如果用户直接尝试输入搜索查询URL,则插件将返回404错误页面

Note that this plugin does not affect the search functionality inside the WordPress admin area. You can still search posts and pages inside your WordPress admin.

请注意,此插件不会影响WordPress 管理区域内的搜索功能。 您仍然可以在WordPress管理员中搜索帖子和页面

方法2。手动禁用WordPress中的搜索功能 (Method 2. Manually Disable Search Feature in WordPress)

This method requires you to add code to your WordPress files. If you haven’t done this before, then take a look at our guide on how to copy and paste code in WordPress.

此方法要求您将代码添加到WordPress文件中。 如果您以前没有做过,请查看我们的指南, 了解如何在WordPress中复制和粘贴代码

You will need to add this code to your theme’s functions.php file or a site-specific plugin.

您将需要将此代码添加到主题的functions.php文件或特定站点的插件中


function wpb_filter_query( $query, $error = true ) {
if ( is_search() ) {
$query->is_search = false;
$query->query_vars[s] = false;
$query->query[s] = false;
if ( $error == true )
$query->is_404 = true;
}
}
add_action( 'parse_query', 'wpb_filter_query' );
add_filter( 'get_search_form', create_function( '$a', "return null;" ) );
function remove_search_widget() {
	unregister_widget('WP_Widget_Search');
}
add_action( 'widgets_init', 'remove_search_widget' );

This code will simply redirect all direct or indirect search queries to a 404 page. It will also hide the search form in your WordPress theme.

此代码将直接将所有直接或间接搜索查询重定向到404页面。 它还会将搜索表单隐藏在您的WordPress主题中。

Search form widget removed

We hope this article helped you learn how to easily disable search feature in WordPress. You may also want to see our mega list of the most wanted WordPress tips, tricks, and hacks.

我们希望本文能帮助您学习如何轻松禁用WordPress中的搜索功能。 您可能还希望查看我们的大型列表,其中包括最需要的WordPress技巧,窍门和hack

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-disable-the-search-feature-in-wordpress/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一、WordPress 七牛云对象存储(简称:WPQiNiu),基于七牛云对象存储与 WordPress 实现静态资源到对象存储,让静态资源包括图片、附件分离 WordPress 根目录,提高网站打开速度。 插件特点 新增支持图像自定义处理 设置水印、编辑图片、压缩 WEBP 等 支持已有图片编辑功能 支持自定义域名设置 支持一键替换静态本地化至对象存储远程 URL 支持一键禁止缩略图 支持自定义任意对象存储目录,一个存储桶可以多网站 支持自动文件重命名 支持本地和对象存储分离和同步 2020 年重构代码改变传统逻辑模型 二、 WordPress 百度搜索推送插件,主要功能:发布新文章时推送文章 URL 至百度搜索资源平台,支持主动推送、自动推送、快速收录,并且完全免费。 百度搜索推送插件特色: 仅发布新文章时才主动提交,修改/更新文章不会重复提交。 与其它同类插件相比较,本插件不会新增自定义栏目,故而不会在数据库留下垃圾数据,不会使数据库变得臃肿。 实时显示提交成功的数量与快速收录当天的提交量。 可设置百度自动推送代码。 本插件为绿色插件,卸载插件后不会留下任何数据。 三、 生成 XML 地图和 HTML 地图。 XML 地图已经通过百度,谷哥,360,搜狗,头条蜘蛛测试。 HTML 地图采取最简模式设计,方便蜘蛛爬取。 可以在每次更新文章时自动更新。 也可以手动更新。 四、 Akismet 会根据我们的全球垃圾评论数据库检查您的评论和联系表单提交,以保护您和您的站点免受恶意内容的侵害。您可以在站点的“评论”管理屏幕上查看垃圾评论。 Akismet 的主要功能包括: 自动检查所有评论,并筛选出垃圾评论。 每个评论都有状态记录,因此您可以轻松查看 Akismet 发现或清除哪些评论与哪些评论被主持人判断是否是垃圾评论。 在评论正文,显示 URL 与显示隐藏或误导性的连结。 主持人可以看到每个用户的批准注释数。 丢弃功能彻底阻止最恶劣的垃圾评论,节省您的磁盘空间并加快您的站点速度。 五、 WP SMTP 插件是国人制作的,设置页面的顶部包含了 Gmail 邮箱、微软邮箱、163 邮箱、QQ 邮箱的设置示例,可以点击对应的图标查看示例截图,其他邮箱设置方法也差不多。 WP SMTP 插件已被 WordPress 官方收录,已自带简体文语言包,而且可以在卸载时自动删除设置数据。 配置好 WP SMTP 以后,你可以发送一封测试邮件,看是否成功。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值