Summary: shorten URLs using, including a markup expression and a function for further coding
Version: 2009-07-22
Prerequisites: uses JSON, which requires PHP 5.2.0
Maintainer: overtones99
Discussion: ShortURLs-Talk

Questions answered by this recipe

  • How can I automatically shorten long urls using online resources like
  • Is there a PHP function I can use to create and feed shortened urls to other functions?


shorten URLs using


"URL Shortening" is a way of converting long, perhaps even multiline, URLs into much, much shorter, more readable ones. It's often used on sites like Twitter where there is a character-limit to messages sent. For example, this cookbook page can also be reached by via the shortened URL,

There are many URL shortening services available, and so far this page only deals with those generated by Feel free to add code for other URL shortening services as well.

The attached code provides two options for URL shortening:

  • (:BitLyUrl ... :) - a markup expression that converts any single enclosed URL into a url
    (:BitLyUrl :)
    will output on the current page
  • bitly_shortened_url($bitLy_login, $bitLy_apiKey, $url) - a function that can be used in other recipes that would enjoy a shortened URL. for example: in a recipe that automatically sends posts to Twitter, or anywhere really where space is tight, one might desire using this function...

To use this code:

in config.php, add the following:

    $bitLy_login = 'yourLogin';
    $bitLy_apiKey = 'yourApiKey';

Note that you must first register for a login and apikey from the site - the registration is free.

Brief Explanation:

This code uses's very basic API, which involves sending a call to the URL, with arguments attached, like so:

For more information on the API, visit
This code was derived from an example on James Cridland's website,

Release notes

  • 2009-07-22: Added to PmWiki Cookbook...

See also


  • overtones99 (feel free to edit this recipe. i'm not always available to maintain this sort of thing, so feel free to dive in and amend this...)


This space is for User-contributed commentary and notes.
Please include your name and a date (eg 2007-05-19) along with your comment.
Optional alternative: create a new page with a name like "ThisRecipe-Talk" (e.g. PmCalendar-Talk).

See discussion at ShortURLs-Talk

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.