Divi WordPress Them — the smartest and most flexible WordPress theme

Back to Top

Automatically Make Links Clickable

Previous Post:

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 myemail@domain.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 wp-includes/formatting.php. make_clickable() filters the comment_text hook with this:

  1. add_filter( 'comment_text', 'make_clickable',      9 );
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:

  1. add_filter( 'the_content', 'make_clickable',      12 );
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 make_clickable().

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:

  1. remove_filter('comment_text', 'make_clickable', 9);
remove_filter('comment_text', 'make_clickable', 9);

Very straightforward, eh?


  1. http://codex.wordpress.org/Function_Reference/make_clic ... _clickable []
Print Article Trackback Trackback to this Article   Subscribe to Comments RSS Subscribe to Comments RSS

16 Opinions for Automatically Make Links Clickable (1 Trackback)

  1. User's Gravatar
    M.K. Safi April 13, 2011 at 11:54 pm – Permalink

    That’s really useful, but the bug that you pointed it out is a real deal breaker. I personally don’t like it when my links are automatically turned into active links, especially when I use example.com for the link.

    By the way, do you use a plugin for the references section within the article, or how do you do it? (Oh, and the option to be notified of follow-up comments would be great!)

    • User's Gravatar
      OddOneOut April 14, 2011 at 2:06 pm – Permalink

      Don’t worry you will be notified automatically (with reply to your comment) ;). About the references, I use a plugin called WP Footnote, for which I wrote a review here, along with some other small-but-cool plugins. Check them out!

      By the way Safi, you look so handsome, haha!

      • User's Gravatar
        M.K. Safi April 14, 2011 at 7:05 pm – Permalink

        Thanks, lol! :oops:

        Oh, and I like that list of small giant plugins. By the way, what operating system do you use and do you write posts directly in WP’s post editor screen? (I use Windows Live Writer)

        • User's Gravatar
          OddOneOut April 14, 2011 at 8:20 pm – Permalink

          I use Windows 7, Ubuntu, OpenSUSE but I’m mainly on Windows 7. And yes I write post directly using the Visual Editor (I like to combine the two), eh… is that a bad thing? :?

          • User's Gravatar
            M.K. Safi April 15, 2011 at 7:59 pm – Permalink

            I couldn’t get used to Visual Editor because it feels a little slow to me. Adding images to posts takes about 10 times longer than with WLW because with WLW, you add images to posts, but they all get uploaded once when you save the draft or publish — you don’t upload images individually like with Visual Editor.

            Also, with WLW, you can set your writing template to look exactly like your post page, so it feels like you’re writing into the front end directly. And of course, it’s a desktop app, so it’s snappier, has all sorts of keyboard shortcuts, has very customizable and smart auto keyword linking and some other things…I love it!

          • User's Gravatar
            M.K. Safi April 15, 2011 at 8:02 pm – Permalink

            Oh, and it also has plugins. Two of my favorite plugins are Dynamic Templates and Paste Code

        • User's Gravatar
          OddOneOut April 16, 2011 at 11:26 am – Permalink

          Damn I can not reply to your last level comment!

          Your 7th comment is a very small nice review there, I think I’m going to switch soon :). Haha now I really think that I need a notification plugin, but I don’t like the one by Mark Jaquith…

  2. User's Gravatar
    S. Georgie April 14, 2011 at 2:24 am – Permalink

    I also agree with the above commenter that such bug is so annoying. Is there a way to fix it?

    • User's Gravatar
      OddOneOut April 14, 2011 at 2:12 pm – Permalink

      @Safi and Georgie: There’s actually a fix for that (which is currently applied to BetterWP.net, the bug you see in my post was done by me, not by the function itself). However, the fix is still very complicated (a lot of regexps!), so I don’t want to post such fix yet.

      We can make the function ignore example.com and yourdomain.com by using a simple strpos function (or you guys can simply omit the http/https, without the schemes plain links will not be made clickable). I will address that issue in the fix ;), so stay tuned!

  3. User's Gravatar
    d4rkcry3r May 1, 2011 at 5:58 pm – Permalink

    Very useful buddy. Thanks for sharing. I also get this problem, sometimes all my post need to identify that link first. But after read your great article, I understand already, thanks again! :)

    • User's Gravatar
      OddOneOut May 1, 2011 at 10:23 pm – Permalink

      You’re welcome!

      Btw, is there any specific reason why you stopped using BWP GXS? Please tell me so I may improve it. Oh, and sorry for spying on your website :P.

      • User's Gravatar
        d4rkcry3r May 1, 2011 at 10:28 pm – Permalink

        Haha, actually I’m used SEO plugin now, so that’s why I’m not use it anymore. I don’t think your plugin have bugs right now, at least for me. Excellent already.. ;)

  4. User's Gravatar
    Kyle G August 24, 2011 at 2:12 am – Permalink

    Hey great post. I have a question, even though you have good information how can you be sure about all this?

  5. User's Gravatar
    Monica October 4, 2012 at 4:31 am – Permalink

    This post is an inspiration for me! Thank you!

  6. User's Gravatar
    Jeffrey November 12, 2012 at 1:20 am – Permalink

    It’s actually a cool and useful piece of information. I am happy that you simply shared this useful info with us. Please keep us informed like this. Thank you for sharing.

  1. The Mighty Mo! Design Co. LLC | Auto-Link urls in WordPress Content - The Mighty Mo! Design Co. LLC | 612-293-8629

    […] to BetterWP.net for this […]

Speak Up Your Mind!

An asterisk (*) indicates a required field and must be filled.

  • Web page and e-mail addresses turn into links automatically.
  • Wrap codes in: <code lang=""></code> or <pre lang="" extra="">
  • Lines and paragraphs break automatically.

Next Post: