By default, WordPress will turn any URL in the comment section into a hyperlink. This means search engine bots and visitors alike can be taken away from your content to benefit someone else. While some of these URLs may be welcome, it also gives spammers and questionable commentors a way to share unwanted or irrelevant content.
Today, I’m going to show you how to disable autolinking in WordPress comments. In this tutorial, you’ll edit a single line of code in your theme.
Don’t worry, it’s a fairly simple procedure that doesn’t require a great deal of programming knowledge. Just copy, paste and update.
Why You Should Disable Autolinking in WordPress Comments
Spam is one of the greatest problems any website owner faces. Without adequate protection, the comment section can easily become littered with spammy content as well as bad links. This gives people a platform to share sites that are loaded with phishing materials or even malware.
Another issue that you might face is people using your comment section as a backlink. This can take visitors away from your website and help the competition gain additional traffic. You want people to stay on your webpages as long as possible.
A good way to protect your WordPress site from spam comments is using Akismet. It will restrict a lot of users, links and webpages from filling your comment section.
Disabling Autolinking in Comments
You have a couple of options available when it comes to making edits to your WordPress theme files. Some will use FTP programs like FileZilla while others will use File Manager in cPanel to access resources. Here, I am going to use the WordPress Editor as it is often the fastest method for minor changes like this.
From the WordPress dashboard, go to Appearance and click, «Editor.»
In the Edit Themes page, click on the «functions.php» file located in the right column under Templates.
Before continuing with the next part of this tutorial, I suggest you copy the entire functions.php file into a Notepad or other text document editor. This gives you a way to create a backup of the file in case something goes wrong.
Just select all of the code, copy it, paste and save the file to your computer.
Scroll to the very bottom of the coding screen until you see «?>».
Input the following code just above the «?>»:
[ht_message mstyle=»info» title=»» show_icon=»» id=»» class=»» style=»» ]remove_filter(‘comment_text’, ‘make_clickable’, 9);[/ht_message]
If you put the code after «?>», it will not work.
Click the «Update File» button to save your changes.
WordPress will now refrain from turning URLs into hyperlinks within the comment section.
What happens when a theme is updated?
When you make changes to the parent theme file templates in WordPress, you run the risk of those alterations being removed during an update. This is because the upgrade often includes replacing old files of the theme itself. This is why a lot of developers would rather use child themes and add custom PHP files. It prevents losing these types of modifications.
Can you use a plugin to remove hyperlinks in the comment section?
If you don’t want to edit the functions.php file, you can always use plugins like Comment Link Remove. This plugin gives you easy-to-follow tools for editing the comment section including a checkbox to disable URLs from becoming hyperlinks.
Can you disable URLs in the comment section in the «Discussion» settings?
The Discussion settings of WordPress do give you a bit of control when it comes to the comment section. Unfortunately, it doesn’t have the ability to disable hyperlinks when people type in URLs. However, you can greatly reduce comment spam and links by adjusting your Discussion settings.
Coding Changes and Your Website
WordPress is quite a flexible system when it comes to adjusting code to suit your needs. If you have an interest in making your own changes in PHP or CSS, you’ll have access to a great deal of versatility. Just make sure you know what you’re doing. The wrong alterations can break your theme or otherwise compromise your website.
What kind of coding changes have you made in WordPress in the past? Do you feel comfortable coding your own customization?