Top 5 ways to Add URL Shortening Services on Your Blog

In recent years,The URL(Uniform Resource Locator) Shortening sites has gained more popularity because of the micro blogging site Twitter.We need Short URLs  for Twitter ,which has character limits.Many Short URL services such as such as ThinyURL, Bit.ly, goo.gl are providing aliases for longer URLs and give redirection to them.In this Article I show you how integrate these URL shortening services in your blog.

Way #1:

Begin with a easy,You can use Word Press plugins to integrate those URL shortening services to your Blog.

URL Shortener plugin allows you to generate shortlinks for post/pages using URL Shortener Services such as Bit.ly, Su.pr, ping.fm, Digg and many others, it’s simple to implement and has many interesting features you can customize as you prefer.

Way#2:

Another  good URL Shortener Plugin is GentleSource Short URL. This plugin creates a short URL from the blog post permalink and stores it in the database. It supports lin.io, unrelo.com, bit.ly, u.nu and tinyurl.com.

Way#3:

Third one  quite interesting plugin ShortURL. This WordPress plugin that allows you to use your blog as your own URL shorterning service by implementing the Short URL Auto-Discovery specification. Your short URLs will be in the form of http://domain/-code.

Way#4:

The next two methods are needed some basic coding skills.If you don’t know about it.I will explain in detail.

Now you can integrate Bit.ly in your WordPress theme.To do that, you need a Bitly account and an API key.

Than, you have to modify your WordPress theme and add this function into the function.php file:

function bitly($url) {
$content = file_get_contents("http://api.bit.ly/v3/shorten?login=YOURLOGIN
&apiKey=YOURAPIKEY
&longUrl=".$url."&format=xml");
$element = new SimpleXmlElement($content);
$bitly = $element->data->url;
if($bitly){
echo $bitly;}
else{
echo '0';
}
}

Then replace  YOURLOGIN with your user name and YOURAPIKEY with your API key of Bit.ly account.

In single.php add this code into the loop to return the shortened URL of the permalink of the current post:

<?php bitly(get_permalink($post->post_id)); ?>

A useful way to use this code snippet is to integrate it with Twitter’s status update link:

<a href="http://twitter.com/home?status=<?php the_title();?>
<?php bitly(get_permalink($post->post_id)); ?> RT @SpicyTricks" target="_blank">

Way#5:

Another interesting way to integrate an URL shortening service on your blog is using TinyURL. TinyURL doesn’t require an account and, unlike Bitly, doesn’t have a rate limit in the API calls.

If you want to integrate it with your WordPress theme add this function into function.php:

function thinyURL($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
}

Open single.php and add the following code into the loop to return the shortened URL of the permalink of the current post:

<?php thinyURL(get_permalink($post->post_id)); ?>

If you want to integrate it with a Twitter’s status update link use this code:

<a href="http://twitter.com/home?status=<?php the_title();?>
<?php thinyURL(get_permalink($post->post_id)); ?> RT @woork" target="_blank">

 

Use TinyURL in your WordPress theme. It’s faster than Bit.ly and doesn’t have limit rate for API calls.So that your site will  load significantly faster.

Raja CRN

Raja CRN is the Founder of CRN Interactive that offers various useful Digital Resources. He has more than 7 years of experience in content Writing and Web development specialized in WordPress. For the past 4 years, He is working on the Linux Administration. In Free Time, He dives into Android Development. He is an engineering graduate in Information Technology. He's also very social, find him at Google+

Copyright © 2009 -16 . SpicyTricks    Designed by ThemePacific