June 20, 2009

Automatically get tr.im urls for your blog posts

trimBefore, we showed you how to automatically get tinyurl’s on your WordPress blog. Well this time, I found a tutorial that will make your WordPress blog automatically generate tr.im url’s for your blog posts.

First to do this, add the following lines to your functions.php file:

function getTrimUrl($url) {
  $tinyurl = file_get_contents("http://api.tr.im/api/trim_simple?url=".$url);
  return $tinyurl;

Now, copy and paste the following code in your single.php file anywhere inside the loop:

$turl = getTrimUrl(get_permalink($post->ID));
echo 'Short Url for this post: <a href="'.$turl.'">'.$turl.'</a>'

There you go! Your WordPress blog will now automatically generate tr.im URL’s.

Previous Post and Next Post

Try HostGator Webhosting for 1 cent for the 1st Month Click here and enter "wordpress"

Leave a reply

* means field is required.