Paulund
2012-09-23 #wordpress

Set Minimum Word Count On Posts

Since Google Penguin has been released there is more of need to create pages which are full of content. What this means for blogs is that no longer can you post something with only a couple of words and expect the post to rank highly for the keywords in the title. You need more content in the entire post with lots of different keywords if you expect to rank at all. With Wordpress there is an action hook on the publishing of a post called publish_post, using this hook you can create a function to make sure you have a minimum number of words in your post. To count the number of words in the post you need to get the current post content and use the PHP function str_word_count() to get the total number of words. You can check to see if the post is under 500 words and if it is you can end the publishing process so the post will not be released.


function minimum_number_words($content)
{
	global $post;
	$content = $post->post_content;
	if (str_word_count($content) < 500 )
	wp_die( __('The current post is below the minimum number of words, it must be over 500 words.') );
}
add_action('publish_post', 'minimum_number_words');