Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

Maximum comment length

Comments longer than 5,000 characters are refused. Spam bots often paste whole articles; real readers rarely write that much.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Category Comments
  • Tested with WordPress 7.1
PHP
<?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.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.