Created
April 18, 2024 14:09
-
-
Save someguy9/e4a0f60227d9fdeb95715b56ec003460 to your computer and use it in GitHub Desktop.
Limit comment length in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Limit the comment length to 6000 characters and a minimum of 50 characters in WordPress | |
add_filter( 'preprocess_comment', 'smartwp_limit_comment_length' ); | |
function smartwp_limit_comment_length( $comment ) { | |
// Limit the comments to 6000 characters | |
if ( strlen( $comment['comment_content'] ) > 6000 ) { | |
wp_die('Comment is too long. Comments must be under 6000 characters.'); | |
} | |
// Require 50 characters to leave a comment | |
if ( strlen( $comment['comment_content'] ) < 50 ) { | |
wp_die('Comment is too short. Comments must be at least 50 characters.'); | |
} | |
return $comment; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment