How to use the URL shortener in

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, 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, so here are the instruction for switching to the URL shortener.

First, update to 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 ="";

    $bitly_args = array(
                            'login' => 'ENTER_YOUR_BITLY_USERNAME',
                            'apiKey' => 'ENTER_YOUR_BITLY_API_KEY',
                            'longURL' => $url,
                            'format' => 'txt',
                            'domain' => '' // either or

    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 username and "ENTER_YOUR_BITLY_API_KEY" with your API key.

This should do it, your URLs should be automatically shortened with your 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 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 URL shortener in

  1. Claude Charpentier says:

    Thanks a lot for this hook !


  2. Adrian Arias says:

    I must be doing something wrong…. I opened my funtions.php file at top and I see this <?php do I put the code here? and also when i put my user name, do I leave the parenthesis (') the 'username'. or with out it.

  3. Lew Ayotte says:

    Hi Adrian,

    Yeah, right below the first <?php line should be fine. You leave the single quote marks around the username and password.

    Let me know if you need further assistance.


    • Adrian Arias says:

      Thanks Lew, but also I need the link to be sent to my facebook. Right now is only sending it to twitter, how do I do that?

      • Adrian Arias says:

        OH! I also try using %URL% so it send the short link to facebook but it didn’t work.

        • Lew Ayotte says:

          Hi Adrian,

          It doesn’t do this by default, actually the next major release is suppose to do this automatically and the option to do will be built into the User Interface.

          So, if you want to do this, you’ll have to update the actual plugin code. Update to the latest version then edit facebook.php. Go to line 648 and change this line:

          $url = get_permalink( $post->ID );

          to this:

          $url = leenkme_get_shortened_url( get_permalink( $post->ID ), $post->ID );

          That should do the trick. If you update the plugin anytime after you edit that code, you’ll need to do it again… until the next major release is released. The version that will include this is 2.0. Let me know if you have any questions.


          • Adrian Arias says:

            Lew is not working, I changed line 648 but when i go to facebook to see the post still shows the long url. here u can see my fanpage –>

  4. Adrian Arias says:

    Lew is not working, I changed line 648 but when i go to facebook to see the post still shows the long url. here u can see my fanpage –>

    • Lew Ayotte says:

      Hi Adrian,

      It’s working fine for me. Can you email me your functions.php file? and your facebook.php file?


      • Adrian Arias says:

        Ok Lew i send it thru your contact form

      • Adrian Arias says:

        I put the file you sent me but now wen click publish Im getting this error –>
        Fatal error: Call to undefined function leenkme_get_shortened_url() in /var/www/vhosts/ on line 649

  5. VBK says:

    How about using a own Link shortner based on yourls?

    • Lew Ayotte says:

      Hey VBK, In the latest version of the plugin, all of this is built into the GUI. It even has YOURLS support built in. But if you have on that isn’t built into the plugin, you can use this same functionality above (with some minor modifications) to add your own custom link shortener.