How to Disable Links in WordPress Comments (NO Plugins)

Here’s how to disable auto-linking in WordPress comments and remove the comment author link. This will keep your comment section free of spam.

Table of Contents

1. Disable WordPress Auto Linking in Comments

People often leave website URLs in the comments. WordPress automatically converts these into links, as shown here:

Need to Remove these Links in WordPress Comments
Need to Remove these Links in WordPress Comments

To prevent this, insert the following code into your theme’s functions.php. Or better yet, create your own WordPress plugin for custom code instead of downloading one of the WordPress store.

remove_filter('comment_text', 'make_clickable', 9);

This simple change will prevent WordPress from automatically creating links out of text URLs in your comments section. After this, the same comment above now looks like this:

Auto Linking Disabled in for WordPress Comment URLs
Auto Linking Disabled for WordPress Comment URLs

While this prevents auto-linking in WordPress comments, it doesn’t stop HTML link tags.

2. Disallow <a> Tags in WordPress Comments

Some people cleverly use an HTML link tag instead of just pasting a URL to create a hyperlink. Here’s an example:

<a href="">This is a link</a>

The browser will convert this HTML into a link even though we disabled auto-linking in the WordPress comments. To prevent this, add the following in the same section where you placed the first piece of code:

function remove_links( $comment_text) {
    $allowed_html = array(
	'br'     => array(),
	'em'     => array(),
	'strong' => array()
	$content = wp_kses( $comment_text, $allowed_html );

    return $content;
add_filter( 'get_comment_text', 'remove_links', 2);

The above code will scan the comment text and only allow visitors to use <br>, <em> and <strong> tags. It will filter out any other tags. With the code in sections 1 and 2, you will disable all links in WordPress comments.

Now there’s only one final step.

3. Remove the Comment Author Link in WordPress

If you want to fully eliminate the ability of your visitors to create links in the comment section, then you should also remove the WordPress comment author link field. By default, WordPress asks your visitor for three pieces of information:

  1. Name
  2. E-mail
  3. Website URL

WordPress converts the third piece of information into a link. Even though it’s a “nofollow” link, many spammers use this to dump low-quality links to their websites. You can remove the third piece of information by adding the following code to WordPress:

add_filter('comment_form_field_url', '__return_false');

This removes the comment author link field in WordPress, and the form looks like this:

Remove Comment Author Link in WordPress
Remove Comment Author Link in WordPress

I prefer to keep the comment author field because it creates a healthy community on my blog and helps me discover new websites. I like to use Cloudflare to filter out spammers instead.

Priority of the “get_comment_text” Filter (Advanced)

In the second piece of code, I set the priority of the “get_comment_text” filter to 2. This is because I use the same filter to allow infinite nested comments, and I don’t want to strip the <a> tag from the “Reply” links I create. So I strip the <a> tags with a high priority, so it executes first and doesn’t interfere with later modifications of the comment. This is a fairly advanced consideration, and most people won’t need to bother with it, but it’s something to keep in mind.

Removing Links in Comments – Final Thoughts

Spam is such a prevalent problem in the comments section that most of us are too cynical to believe a comment section has any value. And if someone is trying to post a link, that’s even worse. Many websites turn off comments entirely. But a good comment section is worth fostering, and it’s worth the effort to strike a balance between being too strict and making it easy for spammers. I suggest you use free Cloudflare firewall rules to block WordPress spam so you don’t put a burden on your site. Keep the faith!

About Bhagwad Park

I've been writing about web hosting and WordPress tutorials since 2008. I also create tutorials on Linux server administration, and have a ton of experience with web hosting products. Contact me via e-mail!

Speak Your Mind