Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Set a minimal character comment limit in Wordpress.
<?php
add_filter( 'preprocess_comment', 'minimal_comment_length' );
function minimal_comment_length( $commentdata ) {
$minimalCommentLength = 20;
if ( strlen( trim( $commentdata['comment_content'] ) ) < $minimalCommentLength )
{
wp_die( 'All comments must be at least ' . $minimalCommentLength . ' characters long.' );
}
return $commentdata;
}
?>
@espellcaste

This comment has been minimized.

Copy link

@espellcaste espellcaste commented Apr 22, 2013

Paulund, where is the place where I can put the exact number of letters so that the snippet can work?

@sheabunge

This comment has been minimized.

Copy link

@sheabunge sheabunge commented Jun 3, 2013

@espellcaste Set the $minimalCommentLength variable to a number of your choosing. Example: $minimalCommentLength = 30; to set the minimum comment length to 30 chars. Replace the already present line.

@paulund

This comment has been minimized.

Copy link
Owner Author

@paulund paulund commented Jun 11, 2013

@bungeshea Thanks for answering that didn't realise @espellcaste left a comment.

@shemul49rmc

This comment has been minimized.

Copy link

@shemul49rmc shemul49rmc commented Nov 28, 2013

if the commenters put comment below the certain length, what will happen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment