DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

If you want to be able to keep a minimum word count for your posts, then just read this recipe. Applying it to your blog can be useful to maintain a clean layout, or ensure your guest writers will not post too short articles on your blog.

Copy the function below and paste it into your functions.php file. The code will automatically raise an error if someone try to publish a post which is below the minimum allowed word count, defined on line 3.

function minWord($content){
	global $post;
        $num = 100; //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');

Thanks to Pippin WIlliamson for submitting this great recipe!

Tags

One Comment

  1. I am using buddypress. It works and comes up as it should but it still publishes! What is wrong?

Leave a Comment

Your email address will not be published. Required fields are marked *