Require minimum comment length in wordpress

Nirvana Free WordPress Theme Review

Add this great snippet by Paul to the functions.php of your wordpress theme and require a minimum comment length. Anything under the limit will return an error message using wp_die "All comments must be at least 20 characters long."

[gum id=”JLYZM” text=”Download an easy to install and use version of this snippet with admin controls for easy use.” price=”$3″]

add_filter( 'preprocess_comment', 'minimal_comment_length' );

function minimal_comment_length( $commentdata ) {
     $minimalCommentLength = 20;

     if ( strlen( trim( $commentdata['comment_content'] ) ) < $minimalCommentLength ){
       wp_die( 'All comments must be at least ' . $minimalCommentLength . ' characters long.' );

     return $commentdata;

Comments  Leave a Reply

  1. Can I add custom div style for error messages?

    1. Unfortunately not that I’m aware of. This error page is not from your template but from wordpress core. I have seen some hacks but all require hacking core files and this is not a good idea.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!