How To Set Minimum Comment Length In WordPress?
January 29th, 2017 | by Ravi Chahar || 2 Comments |
If you’re running a blog then you would know the frustrating moment when people drop one line comment and you delete that.
It’s really unprofessional as people don’t even spend a minute to have a look at the article. They just drop as if someone would welcome them with the rose petals.
Have you ever thought to set minimum comment length in WordPress so that people can’t submit the short comments?
Well, this is something incredible. You will no longer see those useless comments.
What Should You Do To Set This Limit?
You may be thinking about finding a plugin but here, you will get a simple code which will do the work.
As you know, in a WordPress theme there are many files and folders present from which, you have to edit functions.php file.
Whether you open it from the WordPress admin panel or the cPanel of your web hosting account. The choice is yours
Go to Apearance>>Edtior>>functions.php file.
An alternative. Go to cPanel>>file manager>>wp-content>>themes>>theme name>>functions.php file.
Add the code in the file.
add_filter( ‘preprocess_comment’, ‘blogginglove_comment_limit’ );
function blogginglove_comment_limit($comment) {
if ( strlen( $comment[‘comment_content’] ) < 40 ) {
wp_die(‘Your Comment is short. Try to say something valuable’);
}
return $comment;
}
Save the file and close.
Whenever any user tries to add the shorter comment than 50 characters, an error message will appear.
You can edit this error message. As you can see in the code, the message is “Your comment is short, Try to say something valuable”.
You can replace this line with something else. The choice is yours.
And if you’re good with coding then you can replace the whole function shown above. The name of the function can be edited.
Here you’re using a WordPress hook “preprocess_comment” which shouldn’t be touched.
It’s the hook which is taking care of the length of the comment.
You can also try yourself by adding a short comment. If you get an error, congrats, you have successfully set minimum comment length in WordPress.
Are You Excited To Block Those Tiny Comment Authors?
It may be heartbreaking for a few readers who don’t have the habit to say a few more words about the article.
Well, it’s good for you and for them too. People should learn the best way to write quality comments.
Blog commenting is always considered as one of the weapons to build human bonds and you can even get the backlinks from many websites.
Just be original and avoid short comments.
If you have any doubt, feel free to drop a comment
You can also connect with us on Twitter, LinkedIn, and Facebook.
Hey Ravi,
Comment on blogs plays vital role in drawing traffic to individual website and they are also beneficial for establishing new relation with blogger or online marketers. I will definetly give a try to your process for minimum comment lenght in WordPress. Eventually, thanks for sharing your healthy thought with us.
With best wishes,
Amar kumar
Hi Amar,
Blog commenting is always considered a source to connect with others. But many people just drop one line comment which isn’t bearable.
To get rid of those, you should limit the comment length.
Thanks for stopping by.
~Ravi