How to use the bit.ly URL shortener in leenk.me

I just submitted version 1.2.11 to the WordPress repository, so you should see this update coming soon. With this update is the ability to customize your URL shortener. If the URL shortener you use has a basic REST API then it should work.

For now, leenk.me uses a custom WordPress action hook to allow you to have complete freedom of what URL shortener you use. The most common request I get is for bit.ly, so here are the instruction for switching to the bit.ly URL shortener.

First, update to leenk.me 1.2.11!

Second, add this code near the top of your theme's function.php file (after the <?php line):

function custom_leenkme_url_shortener( $api_url, $url ) {

    $bitly_api ="http://api.bitly.com/v3/shorten";

    $bitly_args = array(
                            'login' => 'ENTER_YOUR_BITLY_USERNAME',
                            'apiKey' => 'ENTER_YOUR_BITLY_API_KEY',
                            'longURL' => $url,
                            'format' => 'txt',
                            'domain' => 'bit.ly' // either bit.ly or j.mp
                        );

    return $bitly_api . '?' .  http_build_query( $bitly_args );

}
add_filter( 'leenkme_url_shortener', 'custom_leenkme_url_shortener', 10, 2 );

Third, make sure you replace "ENTER_YOUR_BITLY_USERNAME" with your bit.ly username and "ENTER_YOUR_BITLY_API_KEY" with your bit.ly API key.

This should do it, your URLs should be automatically shortened with your bit.ly account.

If you want to use another URL shortener, contact me and I'll try to get you some code to use instead of the bit.ly example above.

This entry was posted in Custom URL Shorteners, News, plugin, Twitter and tagged , , . Bookmark the permalink.


15 Responses to How to use the bit.ly URL shortener in leenk.me

  1. Pingback: Claude Charpentier

  2. Pingback: Adrian Arias

  3. Pingback: Lew Ayotte

    • Pingback: Adrian Arias

      • Pingback: Adrian Arias

  4. Pingback: Adrian Arias

    • Pingback: Lew Ayotte

      • Pingback: Adrian Arias

      • Pingback: Adrian Arias

  5. Pingback: VBK

  6. Pingback: VBK