How to Create a List of Forbidden Words for WordPress Titles


How to Create a List of Forbidden Words for WordPress Titles
Yee Oconnor

Recently, one of our users asked us how they can add a list of forbidden words for WordPress post titles? If you manage a multi-author blog and want authors to avoid using certain words or phrases, then this tip would come in handy. In this article, we will show you how to create a list of forbidden words for WordPress titles.

How to Create a List of Forbidden Words for WordPress Titles
Dixie Duncan

Recently, one of our users asked us how they can add a list of forbidden words for WordPress post titles? If you manage a multi-author blog and want authors to avoid using certain words or phrases, then this tip would come in handy. In this article, we will show you how to create a list of forbidden words for WordPress titles.

How to Make a List in WordPress of Forbidden Words in Titles
Jennie Conner

$restricted_words = explode(“;”, $restricted_words);
foreach($restricted_words as $restricted_word){
if (stristr( $title, $restricted_word))
wp_die( __(‘Error: You have used a blacklist word “‘. $restricted_word .’” in the post title’) );
}
}
add_action(‘publish_post’, ‘wpb_forbidden_title’, 10, 1);

How to Create a List of Forbidden Words for WordPress Titles
Hector Wise

Here is the quick explanation of the code. Whenever any post is published in your website, the function banned_titles will be called. The list of banned words are stored in the $BannedWords variable. The title of the post is compared with each of the words stored in $BannedWords variable using the PHP function stristr() . This is a Boolean function that will return true if the banned word is found in the title and returns false if it is not found. If the function returns true or if the banned word is found then the WordPress Execution will be terminated and error message will be generated.

Be the first to comment

Leave a Reply

Your email address will not be published.


*