Created
August 23, 2012 11:02
-
-
Save clinton3141/3435551 to your computer and use it in GitHub Desktop.
Limit number of words in wordpress post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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