Skip to content

AutoLinker (by request) for WordPress

Well, someone was asking in the WordPress IRC channel, and it seemed like a simple mod of my acronym replacer … and the rest is source code.

This plugin basically lets you create a list of text that you always want to have linked. So for instance, you can put the World Wide Web Consortium’s acronym in there, and the W3C acronym will always be linked to their website. Or, someone like me can put in a link for (fingers crossed) the Geo Docs site (the doc’s for GeoShell) and have them linked automatically. It’s the perfect solution for lazy people!

You might want to consider altering it so that it only works when the text is within [square brackets], so I put that in as an alternative, look for // SAFER ALTERNATIVE and uncomment the line below, and comment out the two lines above. Hope someone can think of a use for this ;-p

I just released another version which optimizes things by not re-defining the list each time the plugin is invoked. This should save you a ton of lines of code as you define more links. The new version also includes another fix: to allow auto-links to work on the first word.

Edit: May 5, 2006

Even better … get ubernyms and you can build links and acronyms with one plugin :)

19 Comments

  1. [...] [...]

    Monday, June 28, 2004 at 1:58 am | Permalink
  2. [...] [...]

    Monday, June 28, 2004 at 1:53 pm | Permalink
  3. [...] [...]

    Friday, August 20, 2004 at 5:45 pm | Permalink
  4. morydd wrote:

    In viewing my site yesterday, I realized that the links were broken. A simple fix though. in this line
    $text = preg_replace("|\[$match\]|msU" , "<a href="$url">$match</a>" , $text);
    $url was still in as $description
    switch that and it works like a charm. This only applies to the safer option which requires the brackets.
    Thanks again for the help.

    Tuesday, June 29, 2004 at 10:28 am | Permalink
  5. Good catch morydd, thanks. I fixed my local copy, even though it’s commented out :-D

    Wednesday, June 30, 2004 at 7:37 pm | Permalink
  6. donner wrote:

    hi, thanks for the script.
    But line 65 should be commented, or it cannot go. And it wonders me: To comment the line 65, one cannot use // but only /* */. Why??

    Sunday, October 24, 2004 at 1:17 pm | Permalink
  7. chuck wrote:

    So I was looking at this and I noticed that it would be nice to allow a title tag, now I think you can do something like this:
    $autolinker_array = array(
    “my site” => array(“http://www.HuddledMasses.org/” => “The site that made this plugin”),

    Then when you make the link do something like this:

    0“ title=”$aurl1“>$match

    Monday, October 25, 2004 at 2:18 pm | Permalink
  8. donner: well, I’ve been running that on my site without problems as-is, and I can’t imagine how commenting out that preg_replace would help anything. In fact, that line is a fix for a problem that came up with the autolinker text showing up inside a link. (eg: nested &lt;a..&gt; tags).

    chuck:
    Yes, have a look at my current plugin project (heck, have a look at what it’s doing to “my site” in every comment y’all make [LOL] )

    Monday, October 25, 2004 at 8:39 pm | Permalink
  9. andi wrote:

    I would to install your plugin, but become an bug as:
    Warning: Cannot modify header information – headers already sent by (output started at …/wp-content/plugins/autolinker.php:80) in …/wp-admin/post.php on line 342

    What is for a problem? Did the original file use for plugin?

    Tuesday, November 2, 2004 at 4:17 am | Permalink
  10. You left some whitespace in the bottom or top of the file when you copied it over. The line with the &lt;?php and ?&gt; tags have to be the last line in the file, because of where they get included from in WordPress.

    Saturday, November 6, 2004 at 11:40 am | Permalink
  11. Joel,
    I was having a small problem with the autolinker when the target word ended up somewhere as a link parameter (specifically when linking to a firefox plugin).

    So I updated the “default” regex to this:
    $text = preg_replace(”’(?!]*?>)‘si” , “$1$match$2” , $text);

    and it seems to be working perfectly now no matter where the word pops up inside any html tag.

    Here is an example of a url that was breaking:
    https://addons.update.mozilla.org/extensions/moreinfo.php?application=firefox&category=Developer%20Tools&numpg=10&id=60

    it broke while doing an autolink on the word “firefox”

    thanks for the handy plugin.

    Tuesday, April 19, 2005 at 11:57 am | Permalink
  12. Great little plugin and just what I was looking for! I run it under WP 1.5 and it works just as advertised. I have one question though: what should I modify in autolinker.php so that the links always open in a new window? I’m sure there is an easy solution but I know absolutely nothing about php.

    /Anders

    PS. my site

    Saturday, July 2, 2005 at 5:01 pm | Permalink
  13. kapeka wrote:

    Hi,
    fine little plugin. But is there either a way to tell him, that he has only to link “standalone” words, that means no words with brackets or inside a longer word for example: the-google-mod. I am using textile and if there is for example a link with google somewhere in the URL he breaks the link because he makes a link of the word google. Is this easy to implement so that I could do this by my own? I saw the code but this is black magic for me. I see only brackets and signs but I dont understand whats is what there.
    Or is it possible to extend the plugin so that when I write posts in the admin area he shows me what links I have put in the autolinkers php. If this would be possible, the I could easily use the safer version with brackets. With a long list it is hard to remember what I have put it and what not.

    Saturday, July 16, 2005 at 6:04 am | Permalink
  14. Lee wrote:

    Superb plugin, but I do wish you could “opt out” keywords by wrapping them in dollar signs — which I believe is possible with the acronym plugin. “Opting in” (using the square brackets) is a much more involved process requiring the user to make decisions in every single post. It’s very rare that I want to opt-out for example, but when I do, boy I do! ;)

    Wednesday, July 27, 2005 at 7:00 am | Permalink
  15. Lee wrote:

    Oh er, the acronym plugin provided a very useful code hint. I placed this before the loop closing brace in your code:

    $text = preg_replace(”|\[$match\]|imsU” , “$match” , $text);

    That unwraps the anchor element from matched text in brackets ([]).

    Wednesday, July 27, 2005 at 10:12 am | Permalink
  16. Lee wrote:

    Aaaah! I keep hitting problems. For some reason, about 3 out of 75 links “double wrap” (surrounded by two lots of tags). This screws up page validation. I’ve tried resolving it a trillion different ways, but to no avail. I always F*** up something else.

    Gotta reluctantly abandon it now. :( I just wish there was an alternative “autolinker” somewhere. I desperately need one.

    Thursday, July 28, 2005 at 7:10 am | Permalink
  17. Jaykul wrote:

    Lee: can you show me an example?

    I can certainly implement a few more restrictions …

    Saturday, July 30, 2005 at 9:41 pm | Permalink
  18. Well, I fully agree with your comment. :)

    BTW: I visited your blog earlier today and I just wanted to congratulate you on a well presented, and informative resource .

    It’s not often that I come across a web site that offers a wealth of quality. ;-)

    Thursday, August 18, 2005 at 9:48 am | Permalink
  19. Jaykul wrote:

    I’ve finally gotten around to adding a “download” link to my source script. All of my plugins should be simple and easy to download now, just click through to the source and hit the download link.

    Hopefully that will solve all the download problems people have had.

    Friday, September 23, 2005 at 4:35 pm | Permalink

6 Trackbacks/Pingbacks

  1. caffenero.net &raquo; archivi &raquo; Magilinker 0.1 on Thursday, February 17, 2005 at 5:01 pm

    ere il meglio da due plugin giA esistenti ed adatti allo scopo: TextLinker di B. Surkin e Autolinker di J.Bennet. Il tutto funziona piuttosto bene su WP 1.5, [...]

  2. What’s In A Name » autlinker plugin test on Friday, March 11, 2005 at 3:11 pm

    [...] just testing this plugin see if it works XHTML works wonderful in Firefox Source: autolinker No Comments [...]

  3. blog://flatrabbit on Friday, March 11, 2005 at 3:18 pm

    [...] n a yadda, yadda, yadda…yeah I know, bad joke. //EDIT// Let’s alost test the Autolinker Plugin too…. Firefox, Thunderbird, my site….. [...]

  4. AutoLink on Saturday, May 21, 2005 at 7:32 am

    [...] 6”> Oppdatert Det finnes allerede en glitrende god ting som gjor dette. Denne kalles AutoLinker og kan brukes i stedet. [...]

  5. [...] It works!!! Thanks to my friend in the computer, Carrie, for whatever voodoo she worked on Autolinker to make it work! I bow to her WP genius. [...]

  6. Drab as a fool, aloof as a bard » Minor alterations on Tuesday, August 2, 2005 at 5:48 pm

    [...] All this blogging work has given me an idea of what would be useful features in blogging software. Fortunately, no sooner had I thought of the features I wanted, I had found them. Basically I wanted a quick way to mark up common abbreviations and links. The following two WordPress plugins do the trick: acronym plugin and autolinker plugin. [...]