One of the best ways to defend your site against spammers is to limit the number of characters in the commenter’s name, commenter’s URL, and comment content. This tip can be helpful because one of the most obvious signs of spam is the use of long characters in their spam comments. Now you can apply this trick to your wordpress site and keep it spam free.
The other advantage is, this character limit does not require a plugin and it is absolutely important for keep your blog performance runs smoothly, stable and always at the cutting edge of performance. Here we will hack your wordpress engine by adding some php codes. It only takes one step to apply it, just add the code below to wp-comment-post.php file.
Open your wp-comments-post.php file in your blog root directory. Find this code:
if (” == $ comment_content)
wp_die (__ (‘Error: please enter a comment.’));
The code above may not be exactly the same, just find similar codes. Then copy the code below and put on the right after he.
// Start of characters limit
if (strlen ($ comment_author)>25 )
wp_die (__ (‘Sorry, your name is too long, max 25 characters, please go back and try again’));
if (strlen ($ comment_author_url)>40 )
wp_die (__ (‘Sorry, your website is too long, max 40 characters, please go back and try again’));
if (strlen ($ comment_content)20 )
wp_die (__ (‘Sorry, your comment is too short, 20 characters minimum, please go back and try again’));
if (strlen ($ comment_content)>500 )
wp_die (__ (‘Sorry, your comment is too long, maximum 500 characters, please go back and try again’));
// End of the character limit
If you have read my previous article Manual anti-spam – Math challengeYou will see that this trick is basically the same, by hacking the wp-comment-post.php engine, but of course with a different function. You can then combine these two tricks (character limit and manual anti-spam) to make your blog comment much safer from spam. Your blog can now filter out commenters by offering math challenges that can only be solved by humans and limiting the length of their comments.