WordPress: Setting minimum word count for posts

Do you want to specify a minimum word count for posts on your WordPress website or blog? Defining a minimum word count for posts should come handy for multi-author blogs that accept guest posts. Your authors will be forced to submit a post with the minimum number of words.

Copy the code below and paste it in the ‘functions.php’ file of your WordPress theme. If someone tries to publish a post that is below the minimum word count, an error message will be shown using the wp_die() function.

function minimumWords($content){
	global $post;
        $wordcount = 100; //set this to the minimum number of words
	$content = $post->post_content;
	if (str_word_count($content) <  $wordcount)
		wp_die( __('Error: your post is too short. Please increase the word count to'. $wordcount. 'words.') ); ?>
}
add_action('publish_post', 'minimumWords');

Premium WordPress Themes

Reliable Web Hosting

Smart Web Worker strongly recommends HostGator for your website/blog hosting. Sign up for web hosting at just $3.96/month. Use the coupon code "SMARTBLOGGER25" to get 25% discount on any hosting packages. Get an account with HostGator now!

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>