How to set minimum word to published post in WordPress

Hello friends, welcome to my another blog post how to set minimum word to published post in WordPress. When we create a post in WordPress, it is not mandatory to put content in the editor. But if you want to change this functionality then you need to know some basic coding. We can easily do this using WordPress hook add_action and protect someone to post empty content.

Below is the code. Please copy the code and paste it in your theme functions.php



function minWordForPost($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', 'minWordForPost');

Now you know how to prevent empty post content. Please share my post and if you want somethings more comment below.

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •