Skip to content

Instantly share code, notes, and snippets.

@clinton3141
Created August 23, 2012 11:02
Show Gist options
  • Save clinton3141/3435551 to your computer and use it in GitHub Desktop.
Save clinton3141/3435551 to your computer and use it in GitHub Desktop.
Limit number of words in wordpress post
<?php
// put this is functions.php
define('MAX_POST_WORD_COUNT', 200); // change this to set the maximum word count
add_action('save_post', 'limit_post_word_count'); // run the check whenever a post is created or saved using any method
function limit_post_word_count ($post)
{
if (str_word_count($post->post_content) > MAX_POST_WORD_COUNT)
{
wp_die('Your post is too long, it must be less than ' . MAX_POST_WORD_COUNT . ' words long.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment