Maximum comment length
Comments longer than 5,000 characters are refused. Spam bots often paste whole articles; real readers rarely write that much.
<?php
add_filter(
'preprocess_comment',
static function ( $comment ) {
$maximum = 5000;
if ( mb_strlen( (string) $comment['comment_content'] ) > $maximum ) {
wp_die(
esc_html( sprintf( 'Your comment is too long. Please keep it under %d characters.', $maximum ) ),
esc_html__( 'Comment Submission Failure' ),
array( 'response' => 200, 'back_link' => true )
);
}
return $comment;
}
);
In these packs
- Comments: Fewer spam comments and more control: close old posts, set minimum and maximum lengths, a spam trap, no links.