Posted By

nerdsane on 04/26/09


url php wordpress trim wp short tinyurl bitly

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Automatically get short urls for your wordpress posts

 / Published in: PHP

this is how to automatically get short urls for your blog posts in wordpress,

What you need is to decide which tinyurl service you will be using and get its api URL, for example , bit,ly,,

here are the api URLS for the most famous services. : : : :

Note: There are some short url services api's which requires authentication, like , so keep that in mind, but my above services are ok!

  1. /* add the following codes to functions.php file: */
  3. function getShortUrl($url) {
  4. $tinyurl = file_get_contents("API-URL".$url);
  5. return $tinyurl;
  6. }
  8. // remember to replace API-URL in the second line of the above codes with one of the urls mentioned on the comments
  10. /* On your single.php file, paste the following within the loop: */
  11. <?php
  12. $surl = getShortUrl(get_permalink($post->ID));
  13. echo 'Short Url for this post: <a href="'.$surl.'">'.$surl.'</a>'
  14. ?>

Report this snippet  


RSS Icon Subscribe to comments
Posted By: ginoplusio on December 29, 2009

Hi, I've made a function to decode those short urls:

You need to login to post a comment.