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
Recommended Threads
Replies
7
Views
5,109
Replies
0
Views
4,263
Replies
1
Views
2,696
Replies
5
Views
2,176

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