• Resolved techpublish

    (@techpublish)


    Hello fellow WordPressors!

    Does anyone have any suggestions for a plugin that can set character minimums and maximums for comments. Specifically I’m looking to set limits for parent comments, but no limits for child comments.

    Or can settings like these be done with a bit of code, maybe in the functions.php file? Any suggestions or signposting would be appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.

    Thread Starter techpublish

    (@techpublish)

    Thank you very much @faisalahammad

    I’ll test this out and see how it goes. Best wishes & Happy new year!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Parent & Child Comments – Setting character limits’ is closed to new replies.