Apr
24

Automatically shorten urls for your blog posts

tinyThe 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!





Related posts


Want automatic updates? Subscribe to our RSS feed or
Get Email Updates sent directly to your inbox!