How to limit the amount of words in a post?
-
Hello!
On looking around, there was a plugin (word count and limit) which you could use to put a maximum character count on any posts on your site, but this no longer works. I fed it back via the specific plugin forum.
I also found some code, which a few years ago was exactly what I need right now to limit both post title and post size itself:
function maxWord($title){ global $post; $title = $post->post_title; if (str_word_count($title) >= 1 ) //set this to the maximum number of words wp_die( __('You can only use one word for the title!') ); } add_action('publish_post', 'maxWord'); function maxWord($content){ global $post; $num = 500; //set this to the maximum number of words $content = $post->post_content; if (str_word_count($content) > $num) wp_die( __('Don't forget you can only use up to 500 words. Try to trim it down a bit :)) ); } add_action('publish_post', 'maxWord');
Sadly, it appears this is no longer a working function… So my question is this. What can I do to limit the length of both titles and posts by myself and users, please? This is a pretty vital function for me.
Many thanks!
Pip
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘How to limit the amount of words in a post?’ is closed to new replies.