Family Encyclopedia >> Electronics

How to set a minimum word count for WordPress posts

Do you have a blog with several authors? So, you have probably wondered how you can set a minimum number of words for your WordPress posts. In this article, we will share with you a code snippet that allows you to set a minimum word count for your WordPress posts. If a user tries to post a post that is too small, he will return an error telling him that the post is not long enough..

Simply open your theme functions.php file and paste the following code:

function minWord ($ content) global $ post; $ content = $ post-> post_content; if (str_word_count ($ content) < 100 ) //set this to the minimum number of words wp_die( __('Error: your post is below the minimum word count. It needs to be longer than 100 words.') ); add_action('publish_post', 'minWord');

You can change the minimum number of words from 100 to whatever you want. You can also customize the error to make it useful.