Automatically Make Links Clickable
In case you haven’t noticed yet, a plain link in comment text will be automatically converted to a clickable link. For example
http://example.com will be turned into http://example.com, without your visitors having to actually input
<a href="http://example.com">A clickable link</a>. Other types of URLs such as ftp://ftp.domain.com or email@example.com are also converted, which is of course very convenient in some cases.
Such things are made possible by a function named
make_clickable()1 that can be found in
make_clickable() filters the
comment_text hook with this:
add_filter( 'comment_text', 'make_clickable', 9 );
Since it is that simple, let’s try adding the same filter to our post contents and see if it works:
add_filter( 'the_content', 'make_clickable', 12 );
Now try refreshing any singular page to see some magic in action!
The priority of 12 as used above simply tells WordPress to make links clickable for post contents after shortcodes are parsed (which is at priority 11). If you don’t like such behaviour, just change 12 to any number you want. You should take a look at
wp-includes/default-filters.php to choose an appropriate priority for
Being that awesome, however,
make_clickable() has a limitation, which you can clearly see in this clickable link: http://codex.wordpress.org/Function_Reference/make_clic ... _clickable.
See the full stop punctuation mark also included in the link, thus making it broken? To avoid such behaviour you must always have one space plus another character after a plain link, or in other words, never put a plain link like that at the end of a paragraph. In case you must, just make the link clickable the normal way ;).
Of course if you don’t like your visitors to be able to post links that way you can easily remove the filter using:
remove_filter('comment_text', 'make_clickable', 9);
Very straightforward, eh?