Comment exiger une longueur minimale de commentaire dans WordPress
You can enforce a minimum comment length in WordPress by adding the following code to your theme's functions.php file:
function minimum_comment_length( $commentdata ) {
$min_length = 20; // Change this value to set your desired minimum length
if ( strlen( trim( $commentdata['comment_content'] ) ) < $min_length ) {
wp_die( 'Error: Please enter a comment with at least ' . $min_length . ' characters.' );
}
return $commentdata;
}
add_filter( 'preprocess_comment', 'minimum_comment_length' );
After adding this code, comments with a length shorter than the specified minimum will be rejected with an error message prompting the user to make a longer comment.