WordPress Tip: Remove HTML From Older Comments And Disable Links On Comment Form

If your blog is powered by WordPress, you should be well aware of how messy the comments section can get. Spammers try to gain links by posting HTML links in the comments section, which can harm your blog in some situations.

HTML Signature in Comments or Referring Links

Sometimes, I get good comments on my blog articles which I approve because it adds value to the post. But sometimes – right at the end of the comment, the commentator leaves an HTML link as signature so that other readers can check his blog or website.

I think the signature is not at all required because there is always the website URL field where you can enter the URL of your blog and users reading your comment can click through that link to visit your website.

Note: The website URL field in the comment form is no followed in most cases, but what if someone posts a link using HTML tags directly in the comment box? That link will be a do follow link and you should be very careful before approving such links.

Remove All HTML links from Older Comments in WordPress

Just drop the following code in your theme’s functions.php file and bingo ! All older comments on your WordPress blog are converted to plain text and you won’t lose any Google juice because of spam comments.

add_filter(‘comment_text’, ‘wp_filter_nohtml_kses’);
add_filter(‘comment_text_rss’, ‘wp_filter_nohtml_kses’);
add_filter(‘comment_excerpt’, ‘wp_filter_nohtml_kses’);

Convert Older HTML Comments to Plain Text

Some days back I decided to completely disable HTML links in WordPress comment form and turn all the links to plain text. That means, when someone tries to post a link as http://www.abc.com – the link will be visible in plain text but it will not be a hyperlink.

The advantage is that other readers can copy the URL of the plain link and visit the page if they want. This will prevent link spamming on my website’s comment form and I can approve each comment without having to judge the quality of links embedded in the comment.

Tip: Different ways to manage WordPress comments from desktop


Please enter your comment!
Please enter your name here