search ]

Set Minimum Comment Length in WordPress

If you do not want short comments on your posts such as “Thanks!” or “Great article…“, add the following code to your functions.php file and set the minimum character count on line 4:


function minimal_comment_length( $commentdata ) {
    $minimalCommentLength = 20;
    if ( strlen( trim( $commentdata['comment_content'] ) ) < $minimalCommentLength ) {

        wp_die( 'Your comment must contain at least ' . $minimalCommentLength . ' characters.' );

    }

    return $commentdata;
}
add_filter( 'preprocess_comment', 'minimal_comment_length' );

For more comment management, see Show the Total Number of Comments.

Join the Discussion
0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development official logo