WordPress tutorials: Require minimum word count

Wpsnipp – 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.Adding this code to your functions.php of your wordpress theme will require all posts to have a minimum of 100 words before they can be published.

 

 

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');

Leave a comment