
由 WordPress 创建
最近,我们的一位用户问我们如何为 WordPress 帖子标题添加禁用词列表?如果您管理一个多作者博客并希望作者避免使用某些单词或短语,那么这个技巧会派上用场。在本文中,我们将向您展示如何创建 WordPress 标题的禁用词列表。
最近,我们的一位用户问我们如何在WordPress帖子标题中添加禁忌词列表?如果您管理一个多作者博客并且希望作者避免使用某些单词或短语,则此提示非常有用。在本文中,我们将向您展示如何为 WordPress 标题创建禁用单词列表。

为什么要在WordPress中创建禁忌词列表? (Why Create a List of Forbidden Words for Post Titles in WordPress?)
It is not easy to keep all authors informed about your editorial style and policy on a 多作者 site. You can use 编辑流程 to leave editorial comments, add notes, and custom statuses, but it will not monitor your post titles.
在多个作者网站上让所有作者了解您的编辑风格和政策并不容易。 您可以使用“ 编辑流程》来留下编辑评论,添加注释和自定义状态,但它不会监视您的帖子标题。
If an author has publishing rights, then the unwanted words can go live on your website. You can prevent this by 剥夺出版权 from users, but this means more work for you as you will have to review and publish posts yourself.
如果作者具有出版权,那么不需要的词可以在您的网站上发布。 您可以通过取消用户的发布权限来防止这种情况,但这意味着您需要做更多工作,因为您必须自己查看和发布帖子。
话虽如此,让我们看看如何轻松添加 WordPress 帖子标题的禁用单词列表。
话虽如此,让我们看看如何轻松地将禁用单词列表添加到您的 WordPress 帖子标题中。
添加WordPress帖子标题的禁止单词列表 (Adding a List of Banned Words for WordPress Post Titles)
This method requires you to manually add code to your WordPress site. It is recommended for users who know how to 将代码片段从 Web 粘贴到 WordPress 中.
此方法要求您手动将代码添加到WordPress网站。 推荐给知道如何将来自网络的代码片段供用户粘贴到 WordPress 中 。
重要的: Always 备份您的 WordPress 网站 when you are adding a code snippet to your WordPress files.
重要提示 :在向WordPress文件添加代码段时,请始终备份 WordPress 网站 。
Simply add the following code to your theme’s 函数.php file or in a 特定于站点的插件.
只需将以下代码添加到主题的函数.php文件或具体的于在网站的插件中 。
function wpb_forbidden_title($title){
global $post;
$title = $post->post_title;
// Add restricted words or phrases separated by a semicolon
$restricted_words = "word1;word2;word3";
$restricted_words = explode(";", $restricted_words);
foreach($restricted_words as $restricted_word){
if (stristr( $title, $restricted_word))
wp_die( __('Error: You have used a forbidden word "'. $restricted_word .'" in post title') );
}
}
add_action('publish_post', 'wpb_forbidden_title', 10, 1);
Don’t forget to add the words you want to ban in $restricted_words
variable. You need to use a semicolon to separate different words and phrases.
不要忘记在$restricted_words
变量中添加要禁止的单词。 您需要使用分号来分隔不同的单词和短语。
当用户尝试发布帖子时,此代码只会触发一个函数,该函数会检查帖子标题中是否有受限单词。如果它在帖子标题中发现受限制的单词,那么它会向用户显示如下错误:
当用户尝试发布帖子时,此代码只会触发一个函数来检查帖子标题是否包含受限制的单词。如果在帖子标题中发现限制词,用户将看到如下错误:

That’s all, we hope this article helped you learn how to add a list of forbidden words for WordPress post titles. You may also want to see our guide on 如何在 WordPress 中的帖子中要求特色图像.
仅此而已,我们希望本文能帮助您学习如何为WordPress帖子标题添加禁止字词列表。 您可能还希望查看我们的指南, 了解如何要求 WordPress 中的帖子包含精选图片 。
If you liked this article, then please subscribe to our YouTube 频道 for WordPress video tutorials. You can also find us on 推特 and Facebook.
如果您喜欢这篇文章,请订阅我们的YouTube 频道 WordPress视频教程。 您也可以在推特和Facebook上找到我们。
由 WordPress 创建