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?

  • 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

  1. Log in to WordPress with an administrator account.

  2. In the dashboard, go to Appearance → Theme Editor.

  3. From the right‑hand column, select the file named functions.php.

  4. 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 here
            wp_die(__('Error: Your post is below the minimum word count. It needs to be longer than 100 words.'));
        }
    }
    add_action('publish_post', 'minWord');
    

     

  5. 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

  • Always back up your theme files before editing.

  • Consider using a child theme to preserve changes during updates.

  • You can adjust the number 100 to any minimum word count you prefer.

  • This rule applies only when publishing posts, not drafts.

 

 

آیا این پاسخ به شما کمک کرد؟ 0 کاربر این را مفید یافتند (0 نظرات)

Powered by WHMCompleteSolution