Jun 11, 2009 0
Automatically Display a tr.im or TinyURL Link on All Wordpress Posts
Smashing Magazine has a great hack for adding a TinyUrl to each of your blog posts:
In the functions.php file, add the following code:
[code]
function getTinyUrl($url) {
$tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
return $tinyurl;
}
[/code]
And to single.php, add:
[code]
<?php
$turl = getTinyUrl(get_permalink($post->ID));
echo 'Tiny Url for this post: <a href="'.$turl.'">'.$turl.'</a>'
?>
[/code]
To make this compatible with tr.im instead,
[code]
function getTinyUrl($url) {
$tinyurl = file_get_contents("hxxp://api.tr.im/api/trim_simple?url=".$url);
return $tinyurl;
}
[/code]
We tried to use the tr.im functionality with this function over at MuslimMatters, but it began to time out probably due to the rate limit and the number of posts it was being inserted on. In any case, you can see the TinyUrul functioning at MuslimMatters.org.










