Set Maximum Comment Length In WordPress

How To Set Maximum Comment Length In WordPress?

Blog commenting is one of the best weapons to rule this blogosphere. But a few people don’t use it the way it should.

You may get many blog comments which are of 1000 of words and you put them in the spam folder.

Have you ever thought to set maximum comment length in WordPress? It will restrict the spammers to put longer comments.

As you know, longer comments take the time to get loaded so it’s important to set a limit for their length.

Use The Code To Set The Maximum Limit.

For every change, you have to use the functions.php file of your theme.

If you know about WordPress themes then it would be clear that this file is one of the important ones.

Just log in to your WordPress admin panel. Go to Appearance>>Editor>>functions.php file.

If you want to know an alternative then you can also open it from the cPanel of your web hosting account.

Just go to cPanel>>file manager>>wp-content>>themes>>theme name>>functions.php file.

Open and add the code at the bottom of the file.

add_filter( ‘preprocess_comment’, ‘blogginglove_comment_limit’ );function blogginglove_comment_limit($comment) {

if ( strlen( $comment[‘comment_content’] ) > 4000 ) {

wp_die(‘Please keep your comment under 4000 characters. Comment is too long to accept’);

}

return $comment;

}

Save the file.

Whenever anyone tries to add the comment more than 4000 characters, an error would appear.

You can change this error message.

If you’re a techie person then it won’t a problem with such codes.

You can also change the name of the function.

But if you don’t want to play with the code then just copy and paste the code as it is shown.

Use Plugin To Set Maximum Comment Length In WordPress.

A few people are afraid of the codes.

For them, another solution is there. You can use a plugin to set the maximum limit just as you did with the code.

Install and activate the Greg’s Comment Length Limiter plugin and go to its settings.

There will an option to fill the “Upper Length Limit”. You can fill the value according to your choice.

Be default, it’s 3000 characters.

And one of the interesting use of this plugin is that your readers will see the number of characters while writing the comment.

You can adjust its settings for everyone. If you want, you can make an exception for the admin.

How Are You Going To Set The Limit?

I would recommend you to place the code and get rid of this.

As you already know, there shouldn’t be more plugins in your WordPress panel. It affects the page loading time of your website.

But if you’re afraid of codes then go for the plugin. Set maximum comment length in WordPress according to your wish.

You would be interested in reading an article to get more comments on blog posts.

If you face any problem, feel free to ask anything.

You can also connect with us on Twitter, LinkedIn, and Facebook.

by Ravi Chahar

A WordPress Professional and the LinkedIn Influencer. A coder by passion and a blogger by choice. WordPress theme development is his forte. He is your WordPress guy who will teach you how to solve WordPress errors, WordPress security issues, design issues and what not.


Get Free Updates Into Your Inbox

Learn Everything Just Like I Did

SUBSCRIBE



5 comments

  1. Hey Ravi,

    Good tutorial and beneficial for us but you know many people really don’t have interest in codes due to complexity. Plugins are easy to use and they makes work simple. Generally, I also use plugin to maximize but I will definitely give a trial for code. Eventually, thanks for sharing.

    With best regards,

    Amar kumar

    1. Hi Amar,

      I can resonate to your thoughts. Plugins are easy to use but you know that the risk with a plugin is more. You can’t risk your whole website just with one plugin.

      It may conflict with any other plugin. With codes, no such conditions are applied. Just place the code once and forget about the update and all.

      Thanks for stopping by.

      ~Ravi

  2. Ravi,

    That is a nice post, but I dont think I would want to limit the comments to my articles. I would like the reader to have complete freedom to express his/her thoughts. Of course the spam is always a pain to handle, but I would find a few minutes to clean them or approve them based on who it is from.

    Thanks for the article.

  3. Hey Ravi,

    This is good to know!

    I do get a lot of spammers but most of them leave short comments. I do get the long comments from spammers though it this tip should definitely help.

    By the way, I like the look of your blog! It looks much cleaner!

    Have a great week!

    1. Hi Sherman,

      I have faced a lot of spammers in the past few years. It was a headache to deal with those. But now, with the help of this code, anyone can block those lengthy comments.

      Yeah, I have revamped it with better headers, logo and the typography.

      Thanks for your support.

      ~Ravi

Leave a Reply

Your email address will not be published. Required fields are marked *