In this tutorial, we will learn how to disable auto-linking of URLs in WordPress comments.
Why WordPress Autolinks Text URLs in Comments?
WordPress automatically converts text URLs into links which makes it easier to visit the link while moderating comments.
This auto-linking is not stored in your database. WordPress makes URLs clickable when displaying them on screen in admin area as well as comments section below your articles.
Some of these comments are genuine where commenters didn’t know how to add a link in comments. But many spam comments also contain plain URLs pasted directly in the comment text.
Disabling Auto-Link in WordPress Comments
Simply add this single line of code in your theme’s functions.php file or in a site-specific plugin.
remove_filter( 'comment_text', 'make_clickable', 9 );
WordPress does not store plain text URLs as links in the database. Instead it changes them into clickable links on the fly. This code simply disables the filter that makes URLs clickable.
This makes plain text URLs non-clickable in admin area and comments section below your posts. Removing this code will re-enable the auto linking.
If you are adding it to your theme’s functions.php file, then updating your theme will overwrite your functions file.
Also keep in mind that this code only works on plain text URLs. If a user decided to create a link by adding the proper HTML tag, then those links will appear as they should.
If you want to complete turn off any HTML in comments, then take a look at our tutorial on how to disable HTML in WordPress comments.
We hope this tutorial helped you disable auto linking of URLs in WordPress comments.