How to set a minimum comment length in WordPress

The purpose of comments in any website or blog is to allow the visitors to have discussion with each other or with the author of the post. But, some visitors post comments  just to get a back link to their website. Most of these comments are annoying and useless.

In some forums you will notice that they don’t allow visitors to comment below a particular character limit. WordPress doesn’t have such a built-in feature. But you can easily do this using following PHP code snippet.

All you need to do is copy the following code and paste it in your functions.php file.

//Set Minimum Comment length
add_filter( 'preprocess_comment', 'minimum_comment_length' );
function minimum_comment_length( $commentdata ) {
    $minimumCommentLength = 30;
    if ( strlen( trim( $commentdata['comment_content'] ) ) < $minimumCommentLength ){
    wp_die( 'Your comment must be at least ' . $minimumCommentLength . ' characters long.' );
    return $commentdata;

Don’t forget to replace 30 with your custom value.

Set minimum comment length in WordPress without plugin

Set minimum comment length in WordPress without plugin

Useful Read: How to Remove Website URL Field from Comment Form


Leave a Comment.