WordPress: Auto-Add Short URLs via Plugin


28. June, 2009 · 31 Kommentare

Wordpress IconFor sure you have seen those crazy new URLs like “bit.ly/zaSnA” – those “Short URLs” became famous with twitter and its 140 Char limit. When clicked, the Short URLs redirect you to the original URL (also called “Permanent Link”). Lately i stumbled upon a nice tutorial on how to ease the process of generating a Short URL for your blog posts. It aims to do this job automatically so the reader does not have to care about it. It’s realised by a “shortcode” – thats a wordpress feature which allows the author to run some automatic tasks by writing something like:


Please note: There is also a german version of this page.

Flaws of the existing shortcode

After trying out this tutorial i realized it has some flaws – especially when it comes to performance. It generates the Short URL everytime the article is read. This means every user has to wait some milliseconds (or even seconds if the Short URL provider is under load) until the whole page is displayed just because this job gets done over and over again. Besides that it does not provide much options.

My shot on this

So i decided to write my own shortcode. Its added by:


This will generate an tiny URL of your favorite URL Shortener (default: bit.ly) and inserts it at the point of your article where you added the shortcode – so you can put it in the first line of your post or in the very last, you decide! You can choose from these URL Shorteners: “tr.im”, “is.gd”, “bit.ly”, “snurl.com”, “tinyurl.com” and “u.nu”.

It also has a couple of options (so called “attributes”) to give your readers even more info and at the same time more comfort to you. Every attribute can have the value 1 (= active) or 0 (= not active). Here is a list of the attributes with a short description and default values:

  • full – Also shows the Full URL (= permanent link) for this post [Default: 0]
  • link – Displays the URL(s) as HTML link(s) [Default: 0]
  • txt – Auto adds label(s) in front of the URL(s) saying “Short URL for this post:” and vice versa for Full URLs . [Default: 0]
  • short – Shows the Short URL (= permanent link) for this post [Default: 1]

Some examples

[shorturl txt=1 link=1 full=1]

Result: Label text on, links activated and also show Full URL:
[_shorturl txt=1 link=1 full=1]

[shorturl short=0 link=1 full=1]

Result:Does not show Short URL, but Full URL and that one as a link
[_shorturl short=0 link=1 full=1]

Please note that the order of the attributes doesn’t play a role – the result of the following shortcodes is the same:

[shorturl link=1 full=1]
[shorturl full=1 link=1]

Complete auto-mode

The Settings Page of the Short URL Plugin for WordPress (released with version 1.0)

The Settings Page of the Short URL Plugin for WordPress (released with version 1.0)

With version 1.0 of this plugin a Settings page was added. This offers a complete automatic generation of the Short URL so you have to do absolutely nothing, not even enter the shortcode. It also allows to customize the appearance of the Short URL with HTML and CSS Tags. Funky!


The shortcode is only tested on WordPress Version 2.8.


You can download the current version of the Short URL Plugin at the wordpress codex repository.

How to Install

  • Download the Plugin.
  • Upload the shorturl.php into your “wp-content/plugins” folder of your blog.
  • Activate the plugin (“Automatic Short URL”) in your WordPress-Admin Plugins page.
  • Start using the shortcode in your articles where ever you like.
  • Use the Settings page in the WordPress-Admin Interface to further customize the Short URL and workflow.

How to auto add the Short URL at a specific place in the theme

If you’d like to always add the Short URL at the same position and to every post – you can place the following PHP Code into the “wp-content/themes/YOUR_THEME/single.php” at the desired position:

<?php echo(do_shortcode("[shorturl txt=1]")) ?>

But remember: you can activate the complete auto mode, which adds the Short URL add the end of an article – this way there is no need to edit the theme.


1.1.1 // 2009-07-19

  • Store Settings Bug “undefined function ‘empty2zero’” is solved
  • Short URLs are based on the “pretty” permalink
  • From now on Short URLs get generated after the post is published, this way the URL Shorteners’ Databases don’t get spammed by Draft URLs.


  • Added support for “tr.im” Short URLs


  • A Settings Page is added.
  • Support for 5 different URL Shortener Services (is.gd, bit.ly, u.nu, snurl.com, tinyurl.com).
  • Auto-Add functionality (optional!) – no need to write the shortcode by hand anymore.
  • Auto added Short URLs support HTML code, so you can tweak their appearance with CSS classes and more.
  • The Labels added by the “txt” parameter are now editable.
  • A “Reset Settings” function, which removes Settings and URL Caches from posts.


  • Inital release.

Donate if you are happy

If you want to show your appreciation or you would like to motivate me to further improve the plugin, you can send me a donation via paypal.

That’s it for now. Thanks for reading – feel free to ask questions in the comments.

Ihren XING-Kontakten zeigen Artikel bei Xing veröffentlichen
Kategorie:English · Plugin · Tipps · Wordpress
Tags: · · · · · · ·
  • http://twitter.com/kyrd/statuses/2366030215 kyrd (kyrd)

    Add Short URLs to your #Wordpress blog without the hassle http://tinyurl.com/lw4p4w

  • http://twitter.com/weblogtooltips/statuses/2366056226 weblogtooltips (WLTC Tips)

    RT @kyrd: Add Short URLs to your #Wordpress blog without the hassle http://tinyurl.com/lw4p4w

  • http://astore.amazon.de/manometer-21 Manometer

    I am very interested. I have everything ready, and would very much appreciate it.

  • http://www.tatianahairextensions.co.uk hair extensions london

    if only their were more quality websites like yours on the internet, please keep up the good work.

  • http://allaboutwp.com/add-short-urls-via-shortcut-wordpress Add Short URLs via Shortcut – WordPress | All About WordPress

    [...] Direct link to article » » [...]

  • http://plugins.wpuk.co.uk/?p=2697 » Wordpress: Add Short URLs via Shortcut Wordpress Plugins: Just another WordPress weblog

    [...] Go here to see the original: WordPress: Add Short URLs via Shortcut [...]

  • http://wp-popular.com/popular-word-press-websites/wordpress-auto-add-short-urls-via-plugin/ Wordpress: Auto-Add Short URLs via Plugin

    [...] post: WordPress: Auto-Add Short URLs via Plugin Tags: plugin Comments0 Leave a Reply Click here to cancel [...]

  • http://twitter.com/seo_feed/statuses/2453524947 seo_feed (SEO Feed)

    Currently trying out the Short URL Plugin for WordPress http://bit.ly/4a5FMj #wp #plugin

  • http://www.turkbaron.net/ baron

    Works great, thank you

  • http://www.therobinsonsmusic.net/flash/ flash


  • Autos

    great article.thanks!

  • alex

    hi there… great plugin, thanks!

    I’m trying it now but the button ‘store settings’ is not working for me, so is not taking in any changes.

    is it a mac thing? tried in safari and FF but no joy

  • http://exhero.de alexander

    i have the same problem alex has,
    clicking on »store settings« gives me this error:
    Fatal error: Call to undefined function empty2zero() in /*/*/*/wp-content/plugins/shorturl.php on line 145

  • http://exhero.de alexander

    it would also be great if the plugin could use the »good looking« url as destination ;)

  • http://hjacob.com/ Hendrik Jacob

    @alexander & alex: strange thing, it works without a flaw on my WP 2.8 and 2.8.1 … but will investigate and send you an email. thanks for the valuable feedback!

  • alex

    Thanks Hendrik, I don’t even get an error just a blank space where the options were.

    If it helps, I’m on macOSX 10.5.7 – Tested on Safari and Firefox with same results.

    WP 2.8.1

  • http://hjacob.com/ Hendrik Jacob

    Version 1.1.1 is out with a bugfix of the latest Store Settings Bug (thanks to Alexander and Alex!). Update also includes support of the “pretty” permalinks, which are now used to generate the shortened url.

  • Forexboiff

    Great information, I will be linking back to you and going to look around at your other posts.

  • alex

    It works a treat! Thank you so much!
    I’m reluctant to upgrade to WordPress 2.8.2 now


  • 西贝小鱼儿

    Great job.
    Thank you very much~

  • http://adidasshoesoutlet.com Jennason

    it would also be great if the plugin could use the »good looking« url as destination ;)

  • air max shoes

    Hhe into321 article's content rich variety which make us move for our mood after reading this article. surprise, here you will find what you want! Recently, I found some wedsites which commodity is colorful of fashion. Such as xxxxxxxx that worth you to see. Believe me these air max shoes websites won’t let you down.

  • http://vibram4u.com/ moncler outlet store

    Hhe article's content rich variety which make us move for our mood after reading this article. surprise, here <a href=” http://music-ofthesun.com/ ” >wslmart.net you will find what you want! Recently, I found some wedsites which commodity is colorful of fashion. Such as xxxxxxxx that worth you to see. Believe me these websites won’t let you down.

  • mobility scooter

    Great plug in jacob very informative..very nice ideas..

  • Llslll

    I absolutely have enjoyable reading your blog. dont stop posting the excellent quality info!


    MBT Womens Boots

    MBT Womens Shoes

    MBT Mens Sandals

    MBT Mens Shoes

  • http://www.lianasanneh-extensions.com london extensions

    really good i love the information there should be more sites like this

  • Real2play
  • http://twitter.com/netto_info José Ferreira Netto

    Very god! I loved!

  • Reno Fizaldy

    This is a great plugins, but i have problem when i use it

    the excerpt function in the archive.php has been error, and can't show excerpt posts in archive but show the full posts in archive, i'm very confused about it

    when i'm deactivated this plugins the excerpt function in archive.php back to normal, i think the code on this plugins crash with the excerpt code on function.php

    as you know, i used wordpress 3.1

    can you help me about this problem, i think i can't use another short url plugins because this plugins is so very good


  • Gui Tavares

    Hi there,

    this is a great and useful plugin you just wrote. But I and other people are getting errors because the “file_get_contents()” function is not always allowed on the server.
    So you might want to try rewriting the code using the “cURL” method. You can read about it here: http://www.digimantra.com/technology/php/shorten-stats-url-bitly-api-php

    Also note that bitly api is now operating under a different url than the one you used in your plugin code, and a login+APIKey is also needed. So you might want to update that.

  • http://hjacob.com/blog/ Hendrik

    Thanks for your feedback! I will try to build an update as soon as i got some square time.

meet me in the interwebs
Flattr ist ein sehr gut gemachter Micropayment Dienst, der es endlich ermöglicht auf faire Weise Geld zu spenden und einzunehmen.