Set a Minimum Amount of Words to Publish a WordPress Post

There is no minimum amount of words you need to write before you can publish a post.You may want to set a minimum amount of words for posts in order to improve your search engine rankings, improve post quality and if your WordPress installation has multiple authors, deter authors from publishing quick posts that may not have the quality or standards you want, i.e. poor quality.

The Code Snippet

Simply add this to your theme’s functions.php file.

function minimum_words_post($content) { global $post; $content = $post->post_content; $words_amount = 500; if (str_word_count($content) < $words_amount ) wp_die( __('Error: You cannot publish a post that is less than ' . $words_amount . ' words.') ); } add_action('publish_post', 'minimum_words_post');

In this code snippet, the minimum amount of words is 500. This is set in the $words_amount variable. Change it to whatever you want.

The Results

If the post has less than 500 words or whatever you set $words_amount to, you’ll get this response from WordPress:

Minimum Amount of Words for Posts