Simple URL Shortener
Simple URL shortener will shorten a supplied URL using one of a number of online services.
It is the simplest, yet most powerful URL shortening plugin available, with over 100 shortening services available.
Download
Download Simple URL Shortener (v1.4, 19/01/2010)
Changelog
Version 1.0
- Initial release
Version 1.1
- New versions of shared functions added in
- Now uses caching system to save shortened URLs
- Sub-parameter system added to allow for switching off of cache
Version 1.2
- Added 87 new shortening services. pic.gd removed.
- Ability to specify API key and/or login and password details for certain services
- Can now read XML and JSON return formats, not just plain text
- Failed shortening of URLs are no longer cached
Version 1.3
- Added new services – 2Zeus, 9mp, BudURL, HURL, kl.am, Lnk.by, to.vg, url.co.uk
Version 1.4
- Replaced
str_ireplacewithstr_replaceto ensure PHP 4 compatibility
Installation
- Upload the entire
simple-url-shortenerfolder to yourwp-content/plugins/directory. - Ensure the cache folder within the plugins folder is fully writable – ie. change its permissions to 777.
- Activate the plugin through the ‘Plugins’ menu in WordPress.
- There is no options screen.
Configuration
From version 1.1 a cache system is used - please read the installation notes for ensuring that the new caching facility correctly works
The code to access Simple URL Shortener can be put anywhere within your WordPress theme, where you need to convert a long URL to a short one.
Here is an example…
<?php echo simple_url_shortener('http://www.artiss.co.uk','is.gd'); ?>
This will display the is.gd shortened URL for http://www.artiss.co.uk.
There are 2 parameters..
The first parameter is the URL that you wish to have shortened. If left blank it will use the URL of the current post/page.
The second parameter is the shortening service that you want to use. This can be one of the following:
1URL.com, 2Zeus, 3.ly, 307.to, 307.to+key, 9mp, a.gd, a.nf, abbrr, ad.vu, adjix, arm.in, BudURL, bit.ly, bit.ly+key, buk.me, chilp.it, clck.ru, cli.gs, coge.la, coge.la+key, cort.as, cort.as+key, durl.me, fa.by, fon.gs, fwd4.me, gl.am, gurl.es, hex.io, hop.im, href.in, HURL, idek.net, ir.pe, is.gd, ito.mx, j.mp, j.mp+key, kissa.be, kl.am, kore.us, korta.nu, Kots.Nu, krz.ch, l.pr, Lincr, Linkbee, Linkee, LinxFix, liurl.cn, Lnk.by, ln-s.net, ln-s.ru, lt.tl, lurl.no, merky.de, micURL, migre.me, min2me, minilink, MinURL, nbx.ch, ndurl, p.ly, Pendek.in, Piko.me, PiURL, Puke.It, qlnk.net, qr.cx, qux.in, r.im, rde.me, redir.ec, retwt.me, ri.ms, s4c, safe.mn, sai.ly, short.ie, short.to, shortn.me, Shw.me, sl.ly, smsh.me, snkr.me, srnk.net, srs.li, su.pr, su.pr+key, TimesURL, tinyarro.ws, tinyurl, to.ly, toGOto.us, tr.im, tra.kz, twirl, twiturl.de, u.nu, UiopMe, unfake.it, url.co.uk, ur.ly, url.ag, urlBorg, urlG, urlKiss, urlShort, vb.ly, vl.am, vtc.es, xr.com, xrl.us, xxsURL, z.pe, Zi.pe, ZipMyURL, zz.gd
Here is a further version of the original example, but this time with a check to confirm that the plugin is active…
<?php if (function_exists('simple_url_shortener')) : ?>
<?php echo simple_url_shortener('http://www.artiss.co.uk','is.gd'); ?>
<?php endif; ?>
From version 1.1 a cache system is used, whereas the shortened URL is only fetched once from the shortening service provider – after that it is saved and retrieved from a cache in the plugin folder. This greatly improves performance.
However, if you wish to switch it off you can do, via the second parameter. When doing this, the service name must be prefixed too. For example, using the above example, but switching the cache off, you’d type…
<?php if (function_exists('simple_url_shortener')) : ?>
<?php echo simple_url_shortener('http://www.artiss.co.uk','service=is.gd&cache=no'); ?>
<?php endif; ?>
Note the ampersand which is separating the parameters.
Some of the shortening services require additional information. Again, this can be supplied via the second parameter. The three new sub-parameters are apikey=, login= and password= and represent a supplied API Key, a login ID and a password.
bit.ly+key and j.mp+key requires before apikey and login to be specified.
coge.la+key requires login and password to be specified.
307.to+key, adjix, ad.vu, cort.as+key, l.pr, Puke.it, qux.in, tra.kz and urlBorg require the apikey to be supplied.
For example, here is the above example, but now using bit.ly+key as the shortening service…
<?php if (function_exists('simple_url_shortener')) : ?>
<?php echo simple_url_shortener('http://www.artiss.co.uk','service=bit.ly+key&apikey=3003948393993&login=test&cache=no'); ?>
<?php endif; ?>
I’ve not used a valid API key in the above example – you will need to get one for yourself.
Developers
It is envisaged that this plugin is probably more of use to developers who want to include it as part of something else. In particular, this plugin can be called from another – for example, a Social Bookmarking plugin could use this to provide a number of possible URL shortening services.
To this end another routine is provided, validate_url_shortener, which can be used to validate whether a shortening service is valid.
This routine has two parameters. The first parameter is a line of text that you wish to have checked to see if it included a validate shortening service.
The second, optional, parameter is a mask. Use the text {service} to indicate where in the mask the name of the service should appear.
If the shortening service was valid, the name of it will be returned.
Let’s try some examples…
validate_url_shortener('is.gd','');
This will return is.gd if is.gd is, indeed, one of the shortening services that this plugin accepts. Otherwise a null will be returned.
validate_url_shortener('Is there a shortening service in this sentence is.gd','');
Again, this will return is.gd, as it was found within the first parameter.
validate_url_shortener('Start %is.gd% End','%{service}%');
This time a mask has been specified showing that the service should appear within percent signs. As a valid service is found within the first parameter in this format, it will be valid and is.gd will once again be return.
In this example, a null will be specified as the mask condition was not met…
validate_url_shortener('Start is.gd End','%{service}%');
Use this routine in conjunction with the actual shortener to validate passed services before then using them. However, if simple-url-shortener is passed a service that is not valid, it will simply return the original URL.
You haven’t included my favourite URL shortening service!
Just let me know and I’ll possibly include it in a future release. I’m trying to just include the most popular services, as there are hundreds available.
Problems/Queries
Please report any problems, or suggestions for enhancements, to me either via my contact form or by commenting on the appropriate entries on my blog.
Updates
Updates to this and any other of my WordPress plugins will be published on this blog.
Subscribe to my WordPress category feed.
It is invisaged that this plugin is probably more of use to developers who want to include it as part of something else. In particular, this plugin can be called from another – for example, a Social Bookmarking plugin could use this to provide a number of possible URL shortening services.
To this end another routine is provided, validate_url_shortener, which can be used to validate whether a shortening service is valid.
This routine has two parameters. The first parameter is a line of text that you wish to have checked to see if it included a validate shortening service.
The second, optional, parameter is a mask. Use the text {service} to indicate where in the mask the name of the service should appear.
If the shortening service was valid, the name of it will be returned.
Let’s try some examples…
validate_url_shortener('is.gd','');
This will return is.gd if is.gd is, indeed, one of the shortening services that this plugin accepts. Otherwise a null will be returned.
validate_url_shortener('Is there a shortening service in this sentence is.gd','');
Again, this will return is.gd, as it was found within the first parameter.
validate_url_shortener('Start %is.gd% End','%{service}%');
This time a mask has been specified showing that the service should appear within percent signs. As a valid service is found within the first parameter in this format, it will be valid and is.gd will once again be return.
In this example, a null will be specified as the mask condition was not met…
validate_url_shortener('Start is.gd End','%{service}%');
Use this routine in conjunction with the actual shortener to validate passed services before then using them. However, if simple-url-shortener is passed a service that is not valid, it will simply return the original URL.


















Artiss.co.uk is checked by
I want to use this with bw.ly which I own I was going to upload WP to that – so do I understand this URL shortener I have to use one of the ones listed here? How can I use my own?
Hi Larry.
I’d put a facility in to define your own, but there are so many different ways that the API works, it would be difficult to do so.
If it’s one that’s not exclusively for yourself and has an API of some kind, then let me know the details and I’ll get it added.
We’ve been using simple twitter link (and URL shortener since 1.5) to put a twitter link on each of our posts, but it seems like with each update it becomes more and more difficult to have things display properly. Currently, instead of a twitter link, we’re showing an error message:
Simple URL Shortener: Could not update cache file …/simple-url-shortener/cache/c2bb4c9e31be9949ac09e2104a3685b2a3aa60e0.suc
This started happening after the latest update of Simple URL shortener.
Before the last update, this code worked fine for providing a twitter link for us.
Is there something in the new update of Simple URL shortener that isn’t working with Simple Twitter Link? I can’t figure out what to do.
Any help is appreciated.
The first thing to do is to confirm the attributes on the cache folder – ensure it is fully writable.
If that doesn’t work the latest version of the plugin has an option to turn off the caching – that certainly should resolve the issue!
I had the same problem as Local Landing I think and resolved it by creating the cache folder manually since for some reason it didn’t exist after installing the plugin.
Works great now, thanks!
Is this compatible with the Shaun Inman “LESSN” personal URL shortener? It has an API ( which I use on my iPhone with Tweetie2).
LESSN is free URL Shortening service that you can install on your own domain. This means that there’s no fixed URL associated with it – currently, as this plugin stands, that’s not supported.
Besides, I’ve taken a quick look and API details are not obvious. I can see an API key is present and there’s a bookmarklet option available, but I can’t find any API documentation. As much as I’d love to have to install and work it out from scratch via the code… no, I won’t