How to Create a List of Forbidden Words for WordPress Titles

Recently, one of our users asked us how they can add a list of forbidden words for WordPress post titles? If you manage a multi-author blog and want authors to avoid using certain words or phrases, then this tip would come in handy. In this… Read More »

The post How to Create a List of Forbidden Words for WordPress Titles appeared first on WPBeginner.

Recently, one of our users asked us how they can add a list of forbidden words for WordPress post titles? If you manage a multi-author blog and want authors to avoid using certain words or phrases, then this tip would come in handy. In this article, we will show you how to create a list of forbidden words for WordPress titles.

Forbidden words list for WordPress post titles

Why Create a List of Forbidden Words for Post Titles in WordPress?

It is not easy to keep all authors informed about your editorial style and policy on a multi-author site. You can use Edit Flow to leave editorial comments, add notes, and custom statuses, but it will not monitor your post titles.

If an author has publishing rights, then the unwanted words can go live on your website. You can prevent this by taking away publishing privileges from users, but this means more work for you as you will have to review and publish posts yourself.

Having said that, let’s see how you can easily add a list of banned words for WordPress post titles.

Adding a List of Banned Words for WordPress Post Titles

This method requires you to manually add code to your WordPress site. It is recommended for users who know how to paste code snippets from web into WordPress.

Important: Always backup your WordPress site when you are adding a code snippet to your WordPress files.

Simply add the following code 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);

Don’t forget to add the words you want to ban in $restricted_words variable. You need to use a semicolon to separate different words and phrases.

This code simply triggers a function when a user tries to publish a post which checks the post title for restricted words. If it finds a restricted word in the post title, then it will show the user an error like this:

Error shown when a user tries to publish a post with a forbidden word in title

That’s all, we hope this article helped you learn how to add a list of forbidden words for WordPress post titles. You may also want to see our guide on how to require featured images for posts in WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Create a List of Forbidden Words for WordPress Titles appeared first on WPBeginner.

How to Add Character Limit to Post Titles in WordPress

Did you know that the optimal title length is between 55 and 60 characters? It becomes hard to manage the title length when running a multi-author blog. In this article, we will show you how to add character limit to post titles in WordPress. First… Read More »

To leave a comment please visit How to Add Character Limit to Post Titles in WordPress on WPBeginner.

Did you know that the optimal title length is between 55 and 60 characters? It becomes hard to manage the title length when running a multi-author blog. In this article, we will show you how to add character limit to post titles in WordPress.

First thing you need to do is install and activate the Limit Post Titles plugin. Upon activation, simply go to Settings » Limit Post Titles to configure the plugin settings.

Title limit settings in WordPress

You need to enter the character limit and select the post types where you want to enable this character limit. Next, click on the save settings button to store your settings.

You can now create a new post and start typing a post title. You will notice that this plugin will show your character limit and let you know when you exceed it.

Title Limit Exceeded notice

Difference Between Post Title and SEO Title

If you are using an SEO plugin like WordPress SEO or All in One SEO, then you will notice that you can add an SEO title for each post.

SEO Title vs Post title

This SEO title does not change your post’s title. Instead, it is used as the HTML <title> tag for the post. This allows you to provide an alternative shorter title for SEO and more descriptive title for the post title. Both of them provide significant SEO boost. However, most site owners stick to using the same title for both settings to avoid keyword stuffing penalties from search engines.

We hope this article helped you add character limit to post titles in WordPress. You may also want to check our guide on how to prevent duplicate post titles in WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

To leave a comment please visit How to Add Character Limit to Post Titles in WordPress on WPBeginner.