Dukeo » WordPress » HTML In Comments: How To Get Rid Of It On Your WordPress Blog

HTML In Comments: How To Get Rid Of It On Your WordPress Blog

Steven 15 responses WordPress

By default, WordPress allows blog commentators to use HTML in their comments. However, you can easily notice that this feature is mostly used and abused by spammers to create numerous links to their fishy websites.

To get rid of HTML in comments on your WordPress blog, you need to paste the following code in the functions.php file of your WordPress theme:

function plc_comment_post( $incoming_comment ) {
  $incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);
  $incoming_comment['comment_content'] = str_replace( "'", ''', $incoming_comment['comment_content'] );
  return( $incoming_comment );

function plc_comment_display( $comment_to_display ) {
  $comment_to_display = str_replace( ''', "'", $comment_to_display );
  return $comment_to_display;

add_filter( 'preprocess_comment', 'plc_comment_post', '', 1);
add_filter( 'comment_text', 'plc_comment_display', '', 1);
add_filter( 'comment_text_rss', 'plc_comment_display', '', 1);
add_filter( 'comment_excerpt', 'plc_comment_display', '', 1);

If you enjoyed this article,
Get email updates

Join for Free »


  1. Shad

    Wait, so this will get rid of all of the spam links? Cool!! That is definitely super handy.

    1. Sarah

      Oh man no kidding, this will totally help!

  2. Gorman

    Now this will definitely be useful to everyone!

  3. Michelle

    Thanks goodness, this is great!

  4. Buysellwordpress

    If it will really help me to rid myself from these terrible spamming messages, then it’s really great!

    1. Liz

      Word! Spam is awful!

  5. Anon

    You mean you guys don’t appreciate my spam comments?? ;)

    1. Jony

      Umm… no, no not really. lol

    2. Michelle

      Heck no! spam is the worst!

    3. Anon

      Sad face. :(

  6. Dana

    Spam is like the plague of the internet. I would be more than happy to be rid of it!

  7. Samie

    I am definitely guilty of messing up my computer on more than one occasion by clicking on those links. It would definitely be a service to readers to get rid of them on our sites as well!

    1. Sarah

      Me too. And this is why we can’t have nice things. Because Sarah will find a way to break them!

    2. Samie

      Haha that sounds like me as well!

  8. Webdesign Studio

    Very useful, thanks!