Post Pic

How to: Automatically get tr.im urls for your blog posts

Some time ago, I shown you how to automatically get tinyurls for your WordPress blog posts. Today, let’s use tr.im, another (and better) url shortening service.

The first thing to do is to add the following function to your functions.php file:

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

On your single.php file, paste the following within the loop:

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

That's all, enjoy tr.im urls!

Leave a Comment

* Name, Email, Comment are Required