Latest Tech and Tips

How to Create a List of Forbidden Words for WordPress Titles


Recently, one of our customers requested us how they’ll add a listing of forbidden phrases for WordPress put up titles? If you handle a multi-author weblog and wish authors to keep away from utilizing sure phrases or phrases, then this tip would come in useful. In this text, we are going to present you the way to create a listing of forbidden phrases for WordPress titles.

Forbidden words list for WordPress post titles

Why Create a List of Forbidden Words for Post Titles in WordPress?

It isn’t simple to hold all authors knowledgeable about your editorial type and coverage on a multi-author website. You can use Edit Flow to depart editorial feedback, add notes, and customized statuses, but it surely won’t monitor your put up titles.

If an writer has publishing rights, then the undesirable phrases can go dwell in your web site. You can stop this by taking away publishing privileges from customers, however this implies extra work for you as you’ll have to overview and publish posts your self.

Having stated that, let’s see how one can simply add a listing of banned phrases for WordPress put up titles.

Adding a List of Banned Words for WordPress Post Titles

This methodology requires you to manually add code to your WordPress website. It is beneficial for customers who know the way to paste code snippets from internet into WordPress.

Important: Always backup your WordPress website when you’re including a code snippet to your WordPress information.

Simply add the next code to your theme’s capabilities.php file or in a site-specific plugin.

perform wpb_forbidden_title($title){
world $put up;
$title = $post->post_title;

// Add restricted phrases 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 phrase "'. $restricted_word .'" in put up title') );
add_action('publish_post', 'wpb_forbidden_title', 10, 1);

Don’t neglect to add the phrases you need to ban in $restricted_words variable. You want to use a semicolon to separate completely different phrases and phrases.

This code merely triggers a perform when a consumer tries to publish a put up which checks the put up title for restricted phrases. If it finds a restricted phrase within the put up title, then it would present the consumer an error like this:

Error shown when a user tries to publish a post with a forbidden word in title

That’s all, we hope this text helped you find out how to add a listing of forbidden phrases for WordPress put up titles. You might also need to see our information on how to require featured pictures for posts in WordPress.

If you favored this text, then please subscribe to our YouTube Channel for WordPress video tutorials. You can even discover us on Twitter and Facebook.