[ad_1]
Hi @techpublish
Here is a code you can use to set minimum and maximum character limits for parent comments in WordPress:
function check_comment_length( $commentdata ) {
$min_length = 50;
$max_length = 1500;
if ( $commentdata['comment_parent'] == 0 ) {
if ( strlen( $commentdata['comment_content'] ) < $min_length ) {
wp_die( 'Comment is too short. Please try again.' );
}
if ( strlen( $commentdata['comment_content'] ) > $max_length ) {
wp_die( 'Comment is too long. Please try again.' );
}
}
return $commentdata;
}
add_filter( 'preprocess_comment', 'check_comment_length' );This code will check the length of the parent comment and ensure that it is within the specified minimum and maximum limits. If the comment is too short or too long, it will display an error message and prevent it from being submitted. You can adjust the $min_length and $max_length variables to set the minimum and maximum character limits for comments.
Use this code on the child theme’s functions.php file or in a custom plugin file.
I hope this helps! Let me know if you have any questions.
Thank you very much @faisalahammad
I’ll test this out and see how it goes. Best wishes & Happy new year!
