How To Limit Comment Length In WordPress Without Plugin

how to limit comment length in wordpress

If you’re a blogger then you would know the importance of getting the comments.

People try hard to write quality comments on others’ blogs but few of them fail. It’s because they don’t put any value in their comments.

Have you ever thought to create a limit for the number of characters in your comment section? It wouldn’t let anyone drop the smaller comments.

People would only able to submit the comment which would fit the criteria you mention.

Do you know how to limit comment length in WordPress? In this tutorial, you will have the best piece of the code.

You Have To Open The functions.php File of Your Theme

Yes, you read it right.

As you know, all the functions of your WordPress theme are handled by this file. So you have to put the code in it.

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

If you don’t have access to your admin panel or you face any problem with it then use your cPanel.

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

Open this file and add the code at the bottom.

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’);
if ( strlen( $comment[‘comment_content’] ) < 50 ) {
wp_die(‘Your Comment is short. Try to say something valuable’);
return $comment;

I have limited the comment length to minimum 50 characters and maximum to 4000 characters.

You can set the value according to you.

Some people don’t like to set the maximum value so that their readers can have full freedom to express.

Longer and more comments take the time to get loaded. So instead of adding the maximum comment length limit, people like to paginate comments in WordPress.

It’s the matter of choice.

Save the file and you’re done.

Whenever your readers try to add any one line comment with the less character than 50, they will get an error message.

limit comment length

You can edit this error message from the code. Write something you readers can understand the need to write the valuable comments.

No one wants to receive one line comments.

It will save your time to drop those comments in the spam folder manually.

How Many Characters Would You Want To Set For Your Readers

Everyone is different but to run a professional blog, you should take every step to improve the creditability.

Are you going to set the length for the maximum or just for the minimum characters?

If you’re a little bit aware of the WordPress codes then you can easily modify the code shown above. I have used a WordPress hook “preprocess_comment”.

You can change the name of the function if you want. I hope now you know how to limit comment length in WordPress?

If you still face any problem, 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



  1. Hello Ravi,

    Nice article in limiting comment length in WordPress. Had implemented this method on my client website in addition to Akismet plugin. This is an added WordPress security and could possibly reduce spam comment and only get valuable one.

    Keep it up. Thanks for sharing. Have a good day!


    1. Hey Rodney,

      Only a few people can apply this because most of the WordPress users are afraid of using codes. Though you can set the maximum limit using a plugin but not the lower limit.
      Akismet protects the spam comments places by the bots but with this method, you can block unnecessary human comments.
      Thanks for stopping by.

      1. Yes, exactly!

        Though there are a lot of ways. This is one of the most common ones to block those very little comment made by human spammers.

        And guess you already know it.


  2. Hey Ravi,

    This is great and I had no idea you could do that. I am actually going to use this for my site. I’ve created a comment policy on my blog, but I don’t think that anyone takes the time to actually read it.

    I always wake up with those one line comments like “great article” or “thanks for sharing this information.” It gets a little annoying, no one really wants to have a bunch of one line comments, at least I don’t.

    Not really sure what the correct characters of a comment would be. I don’t want people to feel like they have to write forever, but I want them to put a little bit of thought into their comments.

    Thanks for sharing this, I know it will help so many people stop getting those one-line comments we all hate.

    Have a great day 🙂


    1. Hi Susan,

      It’s really frustrating to get those on liner comments. The plugins you use to protect spam comments can’t help you with the human comments. I have tested many plugins but finally had to do it manually.

      Just set the limit you want and there will be a happy vibe. It’s not about restricting your users, it’s about improving the user experience.
      Thanks for taking the time to comment.


Leave a Reply

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