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
24
Replies
4
Views
205
Recommended Threads
Replies
3
Views
2,223
Replies
9
Views
4,110
Replies
0
Views
1,048
Replies
4
Views
2,644

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