How to define a minimum word count per post

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!

Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!

How to define a minimum word count per post

Leave a Reply

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