How to remove unwanted words in Wordpress title automatically

MooseLucifer

Well-known member
Registered
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.

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
Replies
0
Views
64
Replies
0
Views
65
Replies
1
Views
467
Replies
1
Views
416
Recommended Threads
Replies
19
Views
9,412
Replies
9
Views
4,211
Replies
0
Views
2,751
Replies
14
Views
7,097

Latest Hosting OffersNew Reviews

Sponsors

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