Home » Labs » How to get tiny Urls for WordPress automatically  

How to get tiny Urls for WordPress automatically

Filed under Labs

URL shortening is an important part when you play blogs with social media. You can get short url in two ways first is a third party services like tinyurl.com and other is using of a WordPress Plugin. Here we are going to make short urls by first method, that is using tinyurl.com. For doing this place below codes on appropriate places of your WordPress theme as described below.

Add to functions.php

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

Add to single.php

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

Posts you may like: