Skip to content

Instantly share code, notes, and snippets.

@paulund
Created April 7, 2013 17:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save paulund/5331369 to your computer and use it in GitHub Desktop.
Save paulund/5331369 to your computer and use it in GitHub Desktop.
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
Copy link

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

@sheabunge
Copy link

@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
Copy link
Author

paulund commented Jun 11, 2013

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

@shemul49rmc
Copy link

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