As an owner of a blog or a website, you have to manage your site and may want to avoid the using of forbidden words or phrases.

As an owner of a blog or a website, you have to manage your site and may want to avoid the using of forbidden words or phrases.

If you are the all in one of your blog then there have might not anything to be tensed to manage your site but if you are running a multi-author site, then you should think about this matter.

Because it is quite impossible to keep all the authors informed about the editorial style and policy of your site.

You can warn your authors about the policy of your blog, leave editorial comments, add notes or custom statuses, but these will not monitor all the contents.

As a result, you need to review all the contents manually which means more work for you.

Today in this short tutorial, you came to know how to create a list of forbidden words for WordPress titles.

How to Create a List of Forbidden Words for WordPress Titles

At first, add the following snippet of code to the bottommost of your theme’s functions.php file.

function tx_forbidden_title($title){
global $post;
$title = $post->post_title;

// Add forbidden words or phrases separated by a semicolon 
$forbidden_words = "word1;word2;word3";

$forbidden_words = explode(";", $forbidden_words);
foreach($forbidden_words as $forbidden_word){
    if (stristr( $title, $forbidden_word))
    wp_die( __('Error: You have used a restricted word "'. $forbidden_word .'" in the post title') );
    }
}
add_action('publish_post', 'tx_forbidden_title', 10, 1);

In the line of five, insert the words or phrases which you want to ban at the "$restricted_words" variable. And must use a semicolon to separate different words and phrases.

Now save the file and refresh your site.

This snippet of code just triggers a little function. A condition has kept in the "foreach" loop that checks the post title for restricted words when an author tries to publish a post.

If it finds any restricted word in the post title, then it will show the author an error message like the following one.

wordpress-forbidden-words

Conclusion

That’s mainly it. I hope, by this time you have learned how to add a list of forbidden words for WordPress post titles. Have any questions?

Make a shout if you have any question regarding this article through the comment section in below.