was successfully added to your cart.

How to Limit Comment Length in WordPress

By November 4, 2015 Our Blog No Comments

If you have used Twitter, then you already know that you are only allowed to type 140 characters in a single Tweet. It would be nice to have this feature for WordPress comments too. Comments below a certain length or above a certain length are not very helpful. By setting comment length limits in WordPress, you can improve the quality of your comments. In this article, we will show you how to limit comment length in WordPress.

We will add a filter hook to preprocess_comment. This filter is applied to the comment data prior to any other processing of the comment's information when saving a comment data to the database.

[code] add_filter( 'preprocess_comment', 'minimum_comment_length' );

function minimum_comment_length($commentdata) {
if ( strlen( $commentdata['comment_content'] ) > 5000 ) {
wp_die('Comment is too long. Please keep your comment under 5000 characters.');
if ( strlen( $commentdata['comment_content'] ) < 60 ) {
wp_die('Comment is too short. Please use at least 60 characters.');
return $commentdata;

Alternatively you can also use plugin. I recommend Greg's Comment Length Limiter. This plugin provides a configurable limit on the length of comments left in the comment form, with a character countdown displayed for the user and dynamically updated with each keypress.

Leave a Reply

Click to Get Full Access to our entire collection for only $69! Get Access Today