Question from Kim W.: I have a WordPress blog and lots of people are leaving comments on my posts that contain links.
How can I prevent the URLs in those comments from automatically becoming active links?
I really don’t want hackers leaving links to malicious websites via comments on my blog posts!
Thanks for your help.
Rick’s answer: You’re certainly not alone, Kim. Plenty of other bloggers feel the same way you do about the autolinking of comment URLs.
Luckily, there’s an easy way to disable autolinking in your blog’s comments just by adding a single line to one of your theme’s files. (Note: If you make the change to a child theme you won’t have to worry about the change being overwritten by a theme update).
But before I explain how to do make this change, I ask that you read my semi-standard disclaimer:
Making changes to any of the files that make up your WordPress installation can cause serious issues with your blog if even a minor error is made. In fact, a single misplaced character could prevent your blog from loading at all.
That’s why I always strongly recommend making a backup copy of every file you plan to alter before you make any changes.
After reading, understanding and agreeing to the above disclaimer, you can proceed (at your own risk) by following the steps below:
1 – Open the functions.php file that’s located in the directory containing your blog’s theme (or preferably a child theme).
2 – Save a backup copy of the unchanged functions.php file so you’ll be able to quickly reverse any changes should something go wrong.
3 – Add the following line to the very end of the original file:
remove_filter( ‘comment_text’, ‘make_clickable’, 9 );
4 – Save the altered functions.php file and upload it to your server.
That’s all there is to it. If you refresh the page for one of your blog posts that has comments containing URLs, you should see that those URLs are no longer active links (i.e. you can’t click on the URL to open the page it points to).
I hope this helps Kim. Good luck!
Bonus tip #1: Click here to learn how to easily hide the date/time on the comments on your WordPress blog.
Bonus tip #2: Want to make sure you never miss one of my tips? It’s easy! Just…
Click here to sign up for my free Rick’s Daily Tips Email Newsletter!
Would you like to ask Rick a tech question? If so, click here and send it in!
If you found this post useful, would you mind helping me out by sharing it? Just click one of the handy social media sharing buttons below. Thanks a bunch!