For any blog owner, the good management of their blog should be the primary concern. If you are only one person running the blog then there should be no problem. But if you are running a multi-author blog where multiple authors publish articles and posts then you may need some safety precautions. Simply creating a list of forbidden words or phrases for authors, can be one of the useful precautions that you can imply to your blog. In this article we will discuss how to create a list of forbidden words for WordPress titles.
Back Up your files
Before making any changes it will be wise step to back up your theme files. We have tons of articles showing you how to back up your file.
- Backup WordPress with WP-DB-Backup Plugin
- Easily Backup WordPress Site with WP Clone Plugin
- Backup Your WordPress Site with BackUpWordPress Plugin
- Backup and Restore WordPress Site with UpdraftPlus Plugin
- How to Backup your WordPress Site with Duplicator Plugin
- Backup WordPress with WordPress Backup to Dropbox Plugin
- Backup WordPress Database Using MySQL Command Line
- Setup CodeGuard Backup Plugin in WordPress
- Backup WordPress Database using phpMyAdmin
- Backup WordPress Database using cPanel
- How to Backup WordPress Manually and Automatically
How to Create a List of Forbidden Words for WordPress Titles
This is actually very simple. All you have to do is to manually insert few lines of codes to your theme’s functions.php file. If you are wondering where to find functions.php file, then login to your WordPress admin dashboard and go to Appearance > Editor. This will open the theme editor. On the right side you will find the list of all the theme’s files. Select Theme Funnctions file( functions.php) from the right and then place the following code separately at the very end of the file.
function banned_titles($The_Title)
{
$BannedWords = "word1,word2,word3"; /* Insert your banned words or phrase seperated by comma. */
$BannedWords = explode(",", $BannedWords);
global $post;
$The_Title = $post->post_title;
foreach($BannedWords as $BannedWord)
{
if (stristr($The_Title, $BannedWord))
wp_die( __('Error: please remove the forbidden word "'. $BannedWord .'" in post title first!') );
}
}
add_action('publish_post', 'banned_titles', 10, 1);
The most important thing to remember in this code is to insert the words or phrases you want to ban. Replace the word1, word2 and word3 with the words or phase you want to ban and separate the words by comma. Finally don’t forget to save the file.
Here is the quick explanation of the code. Whenever any post is published in your website, the function banned_titles will be called. The list of banned words are stored in the $BannedWords variable. The title of the post is compared with each of the words stored in $BannedWords variable using the PHP function stristr() . This is a Boolean function that will return true if the banned word is found in the title and returns false if it is not found. If the function returns true or if the banned word is found then the WordPress Execution will be terminated and error message will be generated.
Conclusion:
There are many things you can do to safeguard your blog. You can also remove the publishing privileges from other authors to avoid unwanted words to go live in your website. You can enforce the authors to follow the certain editorial style and the policy of your site, add notes and leave editorial comments. We hope this article on how to create a list of forbidden words for WordPress titles was helpful. You can also read our other article on “How to remove spam from WordPress comments”.
Related Posts

Kantiman Bajracharya

Latest posts by Kantiman Bajracharya (see all)
- What are Different WordPress Theme Licensing Terms? - December 21, 2017
- 4 Tips to Optimize Your WordPress for Social Media Share - November 30, 2017
- What is WordPress? Is WordPress Free? Why is WordPress so popular? - November 22, 2017