How To Define A Minimum Word Count Per Post On Your WordPress Blog

You may want to make sure that all the posts published on your WordPress blog have a minimum word count, especially if you are allowing guest contributors to post on your blog. This can also help maintaining a clean layout and a decent post quality.

To enable this WordPress hack, paste the following code in your functions.php file. This code will automatically raise an error whenever someone tries to publish a post which doesn’t have more words that the minimum number of words defined.

function minWord($content){
  global $post;
        $num = 300; //set this to the minimum number of words
  $content = $post->post_content;
  if (str_word_count($content) <  $num)
      wp_die( __('Error: your post is below the minimum word count.') );
}
add_action('publish_post', 'minWord');

You’re all set. The 300 number means that your posts will need to have a minimum of 300 words. If you want to change the minimum word count, feel free to change this number.

Sté Kerwer
Article written by Sté Kerwer (1993 Posts)
Bonjour from a french guy. My name is Sté Kerwer and Dukeo is my blog. I do most of the heavy lifting in here but from time to time, you may see some guest posts. To receive updates from Dukeo, follow us on Twitter or like us on Facebook.
If you enjoyed this article, Get email updates
JOIN FOR FREE

2 Comments (Add one)

  1. Affiliate Manager
    Affiliate Manager

    Interesting. I think there may be instances where you might not want this, but overall it’s definitely important to keep your post count high. I usually go for at least 500 words on my articles. Thanks for the programming tip!

    1. Sté Kerwer

      Of course if your websites is about haikus, you don’t want to use this snippet of code ;) But overall, it allows you to make sure your blog posts have a minimum length without having to manually check.

Leave a Reply

When posting a comment, please use your personal name, not your business name. I find it a lot more interesting to talk with people instead of talking with brands.