/ 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 rinyurl.com , bit,ly, tr.im,
here are the api URLS for the most famous services.
tinyurl.com : http://tinyurl.com/api-create.php?url=
is.gd : http://is.gd/api.php?longurl=
href.in : http://href.in/api.php?create=
tr.im : http://api.tr.im/api/trim_simple?url=
Note: There are some short url services api's which requires authentication, like bit.ly , so keep that in mind, but my above services are ok!
                What you need
is to decide which tinyurl service you will be using and get its api URL,
for example rinyurl.com , bit,ly, tr.im,
here are the api URLS for the most famous services.
tinyurl.com : http://tinyurl.com/api-create.php?url=
is.gd : http://is.gd/api.php?longurl=
href.in : http://href.in/api.php?create=
tr.im : http://api.tr.im/api/trim_simple?url=
Note: There are some short url services api's which requires authentication, like bit.ly , so keep that in mind, but my above services are ok!
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
/* 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: */
<?php
$surl = getShortUrl(get_permalink($post->ID));
echo 'Short Url for this post: <a href="'.$surl.'">'.$surl.'</a>'
?>
Comments
 Subscribe to comments
                    Subscribe to comments
                
                