By default, WordPress allows certain HTML tags within the comments such as <a> <em> <strong> etc. If you notice a lot of SPAM comments also contain these tags. Most SPAM comments are made by bots and scripts, which are using HTML tags. If you simply disable HTML from your WordPress comments, it can prevent a lot of SPAM. In this tutorial we will show you how you can disable HTML tags in your WordPress comments.

This tutorial will only disable active HTML tags. So someone can still post something like:


And it will show up, but the tags will not be functional. So if someone uses the strong tag, it won’t bold the text. Besides not many SPAM bots have time to do this because this way takes up a lot of time and it is not beneficial for them.

All you have to do is simply open your functions.php and add the following code:

01 // This will occur when the comment is posted
02 function plc_comment_post( $incoming_comment ) {
04 // convert everything in a comment to display literally
05 $incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);
07 // the one exception is single quotes, which cannot be #039; because WordPress marks it as spam
08 $incoming_comment['comment_content'] = str_replace( "'", '&apos;', $incoming_comment['comment_content'] );
10 return( $incoming_comment );
11 }
13 // This will occur before a comment is displayed
14 function plc_comment_display( $comment_to_display ) {
16 // Put the single quotes back in
17 $comment_to_display = str_replace( '&apos;', "'", $comment_to_display );
19 return $comment_to_display;

Source – The original author also offers a plugin that you can download from his site.

The reason why this way is better is because it does not require you to change the core files. If you want to edit your core files then you may go to wp-includes/kses.php and edit the codes there. (This is not Recommended, but it is here for the sake of knowledge. (WP Codex for more details)

From http://www.wpbeginner.com/