- Joined
- May 20, 2016
- Messages
- 149
- Points
- 28
If you are a website owner and having many editors posting articles on your blogs, it is hard to avoid unwanted words that your members can post into wordpress title of posts. Today, I'll share with you a small code can help you filter out words that the other members accidentally add into the title before they can be published.
To use, you just enter sensitive words to the variable $restricted_words to filter unwanted words in Wordpress title.
Good luck!
Code:
function wpb_forbidden_title($title){
global $post;
$title = $post->post_title;
// add your words into restricted_words below
$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);
To use, you just enter sensitive words to the variable $restricted_words to filter unwanted words in Wordpress title.
Good luck!