How to Disable HTML in WordPress Comments Area
SHARE THIS

By default, WordPress allows certain tags in comments. Commenters can add links, style text in bold and italics, add tables, and more. This can be quite useful until the spammers pay you a visit.

If you simply disable HTML from your WordPress comments, it can prevent a lot of SPAM. In this quick tip we will show you how to disable HTML tags in your WordPress comments.

Open your functions.php and add the following code:

// This will occur when the comment is posted
function plc_comment_post( $incoming_comment ) {

// convert everything in a comment to display literally
$incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);

// the one exception is single quotes, which cannot be #039; because WordPress marks it as spam
$incoming_comment['comment_content'] = str_replace( "'", ''', $incoming_comment['comment_content'] );

return( $incoming_comment );
}

// This will occur before a comment is displayed
function plc_comment_display( $comment_to_display ) {

// Put the single quotes back in
$comment_to_display = str_replace( ''', "'", $comment_to_display );

return $comment_to_display;

If you prefer you can always download the plugin from the original source.