Return to Snippet

Revision: 13491
at April 26, 2009 07:49 by nerdsane

Initial Code
/* add the following codes to functions.php file: */

function getShortUrl($url) {
  $tinyurl = file_get_contents("API-URL".$url);
  return $tinyurl;

// remember to replace API-URL in the second line of the above codes with one of the urls mentioned on the comments

/* On your single.php file, paste the following within the loop: */
$surl = getShortUrl(get_permalink($post->ID));
echo 'Short Url for this post: <a href="'.$surl.'">'.$surl.'</a>'

Initial URL

Initial Description
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!

Initial Title
Automatically get short urls for your wordpress posts

Initial Tags
url, php, wordpress

Initial Language