How to Remove Hyperlinks from WordPress Comments

Comments are important part of blog. Comments allows users to give their feedback and discuss about the article. But with comment comes spam. Out of many types of spam, links in WordPress comment is a major one. In WordPress commenting section whenever user enters URL as a text in comment field. WordPress automatically convert them to clickable URLs. This article shows how to remove hyperlinks from WordPress comments.

How to Remove Hyperlinks from WordPress Comments

Such auto links bear a no-follow relationship attribute in general links. This means Search Engines do not pass the link value when it comes to search engine rankings. Spam can discourage your readers and divert your visitors away resulting in less traffic. In this article we will talk about all the ways to disable auto linking in URL in WordPress Comment

How to Remove Hyperlinks from WordPress Comments

There are various ways and methods to remove or disable links from WordPress comments.

Disabling Auto-Link in WordPress Comments

You can disable URL from the comment with a single line of code in function.php file.

remove.filter(‘comment_text’,’make_clickable’, 9);

This removes filters that make URL clickable. Now, URLs written in plain text will not be clickable in your comment area as well as in your admin dashboard. This code will work on previously placed link as well. You can remove the code anytime if you want to enable auto linking of URL again.

Disable HTML tag in Comment

If your spam commentators decide to add URL links using HTML anchor tag like <a href="">www.example.com</a>
then again this link will be displayed as URL. The solution for this is to add few more lines of code in the function.php file.

/* This will occur when the comment is posted */

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);
 }

/* This will occur before a comment is displayed */

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

This can prevent many types of  HTML Entities from being included in comment. There are some plugins available like Peter’s Literal Comments  that can disable the HTML tag in comments without writing codes. There is one more way commenters can insert links in comment. If they decide to use  something like

&lt;a&gt; &lt;/a&gt;

this will still be displayed as link but it won’t be functional. Beside lot of spams are posted by spams bots which do not use this technique. So it is not that harmful.

Disable Link Input field in Comments

A general comment form has name, email, website and comment fields. Some fields like website field allows commenters to add URL. In this way again, URL is injected in comment section. You can completely remove the website field too. Removing it will not allow any kind of clickable URL to be input. To disable link input field in comment, go to function.php and add the following code.

add_filter('comment_form_default_fields','disable_comment_link');
function disable_comment_link($inputs) {
unset($inputs['url']);
return $inputs;
}

Using Plugins to disable auto linking of URL in WordPress comment

If you want to use plugin you can try Disable Comment URL plugin. The plugin helps you to remove URL from comment. The plugin doesn’t require any special configuration. After installation it will start removing links from comment.

Also Read:   Show Related Posts in WordPress with Advanced Random Posts Widget

How to Remove Hyperlinks from WordPress Comments

No Comment Links  is another simple plugin which disables automatic parsing and creation of clickable links in comments, including HTTP, ftp, and e-mail links.

How to Remove Hyperlinks from WordPress Comments

If You wish to protect your comments from all kinds of spams, you can check our article for making WordPress comment more safer with the title “How to Remove Spam from WordPress Comments”. Also if you find comment section getting out of hand in certain post and wish to remove it, you can check our another article on “How to Disable WordPress Comments in Posts and Pages”.

 

The following two tabs change content below.
Kantiman Bajracharya

Kantiman Bajracharya

Kantiman Bajracharya is a freelance web developer. He is a computer geek who has a Bachelor’s degree in Computer Engineering. He has earned lots of satisfied customers while working for numerous successful projects. He is also a WordPress theme creator and web article writer. On free time he likes reading philosophy books, traveling and playing chess.

Share This Post