How to Create a List of Forbidden Words for WordPress Titles395

How-to-Create-a-List-of-Forbidden-Words-for-WordPress-Titles
Author: InfoBeep - November 28, 2017 | subject to copyright

Why create a list of forbidden words for post titles in WordPress?

You may don’t want some of the words to be used in post titles your WordPress site. But, whenever you have a multi-author site, it become difficult for you to check the writing of every author. In this case, creating a list of forbidden words for post titles can be useful.

Adding a list of banned words for WordPress post titles

Inorder to add a list of banned words for WordPress post titles, add the codes given below to your theme’s functions.php file or in a site-specific plugin.

function wpb_forbidden_title($title){

global $post;

$title = $post->post_title;

// Add restricted words or phrases separated by a semicolon

$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);

(note: add words you want to ban in $restricted_words variable, if you are using multiple word or phrases separate them with semicolon sign)

(note: backup your site data before you add a code snippet to your WordPress files)