Automatically get tr.im urls for your blog posts

By | June 20, 2009

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:

<?php
$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.

Category: Uncategorized