How to remove unwanted words in Wordpress title automatically

MooseLucifer

Active member
Joined
May 20, 2016
Messages
73
Points
18
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.

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!
 
Latest Threads
  • Deleted
  • Deleted by fwh
Replies
0
Views
4
Replies
0
Views
26
  • Deleted
  • Deleted by fwh
Replies
0
Views
4
Replies
2
Views
44

Latest postsNew threads

Latest Hosting OffersNew Reviews

Sponsors

Latest Blog ArticlesMost Viewed Threads

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top