WordPress tutorials: Create tiny URLs automatically

Wpsnipp – Using short url tools have become common place across the web in recent years.Add the first section of code into your functions.php. Adding the second section of code into your single.php template file will automatically create and display the tiny url.



function getTinyUrl($url) {
$tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
return $tinyurl;

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

Leave a comment