Apparently I’ve been doing things the hard way in my WordPress-related coding. I’ve been using regular expressions to turn URLs into clickable links, when WordPress already has a built-in formatting function to do just that.
Meet make_clickable(). All you have to do is pass a string to it, and it will return the string, but with any web URLs, email addresses or FTP URLs turned into HTML links.
$text = 'This is a cool link: http://www.webmaster-source.com';
This is a cool link: http://www.webmaster-source.com. Easy enough, and certainly a more efficient method than writing your own function to do it.