In this article, we will share with you a snippet that lets you set a minimum Word count for your WordPress posts. If a user tries to publish a post that is too small, then it will return an error telling them the post is not long enough.

Open your theme’s functions.php file and paste the following code:

<?php
 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 may change the minimum number of words from 100 to whatever you like. You can also customize the error to make it helpful.


Post Tags


About The Author


Leave a Reply

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

home