Setting minimum word count for WordPress posts
By default, WordPress does not enforce a minimum word count for posts. If your site accepts content from multiple authors, you may want to ensure posts meet a minimum length for quality and SEO purposes. On ruachost.com, you can enforce this by adding a simple PHP function.
Why Set a Minimum Word Count?
Section titled “Why Set a Minimum Word Count?”- Ensures consistent content quality.
- Helps with SEO by avoiding thin content.
- Encourages authors to provide more detailed posts.
Steps to Add Minimum Word Count Rule
Section titled “Steps to Add Minimum Word Count Rule”-
Log in to WordPress with an administrator account.
-
In the dashboard, go to Appearance → Theme Editor.
-
From the right‑hand column, select the file named functions.php.
-
Scroll to the bottom of the file and add the following code:
function minWord($content) {global $post;$content = $post->post_content;if (str_word_count($content) < 100) { // set minimum word count herewp_die(__('Error: Your post is below the minimum word count. It needs to be longer than 100 words.'));}}add_action('publish_post', 'minWord'); -
Click Update File to save changes.
✅ Now, if a post has fewer than 100 words, WordPress will display an error message and prevent publishing.
Important Notes
Section titled “Important Notes”- Always back up your theme files before editing.
- Consider using a child theme to preserve changes during updates.
- You can adjust the number
100to any minimum word count you prefer. - This rule applies only when publishing posts, not drafts.