Title: Limit Word Count
Last modified: August 20, 2016

---

# Limit Word Count

 *  [Jim S.](https://wordpress.org/support/users/stitzelj/)
 * (@stitzelj)
 * [14 years ago](https://wordpress.org/support/topic/limit-word-count/)
 * I need a plugin that limits an author to a post of maximum length (i.e. no more
   than 1000 words) for a project I’m putting together. Specifically, I’m looking
   for a plugin that allows an author to enter any number of words in the editor
   but that won’t let them publish the post until it has been edited down to the
   maximum number allowed (or lower). Unfortunately, I don’t have quite enough know-
   how to code something like this. Anyone able to write a plugin like this — or
   at least give me some direction as to how to get started or where to hook it 
   in?

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [luckdragon](https://wordpress.org/support/users/luckdragon/)
 * (@luckdragon)
 * [14 years ago](https://wordpress.org/support/topic/limit-word-count/#post-2778153)
 * the problem with most plugins like that is it doesn’t strip out the html code
   when calculating, so
    `<strong>hi there</strong>` would actually count as 25 
   characters, and
 *     ```
       <img src="http://yourdomain.com/wp-content/plugins/whatever/images/filename.jpg" width="100" height="100">
       ```
   
 * would count as 107 characters
 *  Thread Starter [Jim S.](https://wordpress.org/support/users/stitzelj/)
 * (@stitzelj)
 * [14 years ago](https://wordpress.org/support/topic/limit-word-count/#post-2778155)
 * Well, I don’t need a character count, but a word count. The content being submitted
   would be short fiction, so HTML markup would be minimal.
 *  [luckdragon](https://wordpress.org/support/users/luckdragon/)
 * (@luckdragon)
 * [14 years ago](https://wordpress.org/support/topic/limit-word-count/#post-2778156)
 * I’m not sure, I’ve seen jqueries that monitor the “comment” field, but not sure
   about the post one.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [14 years ago](https://wordpress.org/support/topic/limit-word-count/#post-2778184)
 * You want to hook the filter ‘wp_insert_post_data’. Your function will be passed
   an array with all the post data. If you assigned the array to `$draft`, you might
   be most interested in the value of `$draft->post_content_filtered`. Your function
   will need to somehow get a word count out of this value.
 * Unresolved is how to handle a high word count. I think if you just did a wp_die(),
   the user can just use their back button and all of the form data is still retained.
   Certainly, more elegant solutions are possible.
 *  [nbernhard](https://wordpress.org/support/users/nbernhard/)
 * (@nbernhard)
 * [14 years ago](https://wordpress.org/support/topic/limit-word-count/#post-2778187)
 * Could you use jQuery or something similar to disable the ‘publish’ button until
   the word count is acceptable?
 * You would still need a fallback for those who do not use Javascript, but this
   may be a good solution to start with.
 *  [nbernhard](https://wordpress.org/support/users/nbernhard/)
 * (@nbernhard)
 * [14 years ago](https://wordpress.org/support/topic/limit-word-count/#post-2778188)
 * For starters, this function would return the string without the HTML tags:
 *     ```
       jQuery.fn.stripTags = function () {
           return this.replaceWith(this.html().replace(/<\/?[^>]+>/gi, ''));
       };
       ```
   
 *  Thread Starter [Jim S.](https://wordpress.org/support/users/stitzelj/)
 * (@stitzelj)
 * [13 years, 12 months ago](https://wordpress.org/support/topic/limit-word-count/#post-2778392)
 * Doesn’t the editor already count the number of words in a post? How do I tap 
   into that?

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Limit Word Count’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 7 replies
 * 4 participants
 * Last reply from: [Jim S.](https://wordpress.org/support/users/stitzelj/)
 * Last activity: [13 years, 12 months ago](https://wordpress.org/support/topic/limit-word-count/#post-2778392)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
