Automatically Shorten your Permalink using Bit.ly services


Sponsored Links






WordPress Beginner show nicely tutorial about How To Automatically Shorten your Permalink using Bit.ly services. Why we need to shorten our URL? Shorten URL is good to share on many social web, social news, social media and social network such as Twitter, Facebook, Digg and many more..

Shorten your Permalink using Bit.ly - Marie Digby Photo

Shorten your Permalink using Bit.ly - Marie Digby Photo


Before we began using this tutorial, you need create your own Bit.ly API Key on this page.. after finish paste this code on your functions.php

<?php
/* Based on code from David Walsh – http://davidwalsh.name/bitly-php */
function make_bitly_url($url,$format = 'xml',$version = '2.0.1')
{
//Set up account info
$bitly_login = 'YOUR LOGIN HERE';
$bitly_api = 'YOUR API KEY HERE';
//create the URL
$bitly = 'http://api.bit.ly/shorten?version='.$version.'&longUrl='.urlencode($url).'&login='.$bitly_login.'&apiKey='.$bitly_api.'&format='.$format;
//get the url
$response = file_get_contents($bitly);
//parse depending on desired format
if(strtolower($format) == 'json')
{
$json = @json_decode($response,true);
return $json['results'][$url]['shortUrl'];
}
else //For XML
{
$xml = simplexml_load_string($response);
return 'http://bit.ly/'.$xml->results->nodeKeyVal->hash;
}
}
?>

You need to change your LOGIN and API key on the code above. After finish, open your single.php and paste this code under start on your WordPress Loop

<?php
//Check for post's shortened URL. Used with twitter feedback.
if(get_post_meta($post->ID, "short_url", true) != ""){
//Short URL already exists, pull from post meta
$short_url = get_post_meta($post->ID, "short_url", true);
}else{
//No short URL has been made yet
$full_url = the_permalink();
$short_url = make_bitly_url($full_url);
//Save generated short url for future views
add_post_meta($post->ID, 'short_url', $short_url, true);
}
?>

And the last thing to do, paste this code anywhere on your loop

<?php echo $short_url; ?>

I hope this tutorial work on you, if you have any question you can discuss it here or contact WordPress Beginner.

Subscribe to Full RSS Feed

RSS FeedIf you thing this article useful, please consider subscribing to our RSS Feed or e-mail updates and stay updated with us. You can also follow @WPTricksNet on twitter for latest updates.

About WP Tricks

We are WordPress Family, we collected and writed useful tips and tricks for you WordPress. We share it for you...

Related Tips and Trick from Local Data and on The Net

How To Add WP Login Link to Your Navigation Menu Automatically

I will show you easier tutorial add WP login Link to Your Navigation Menu Automatically. We only needed to some function to our functions.php and WP Login link will be automatically added into our WordPress Navigation Menu. Description About wp_loginout() … Read More

Automatically Create a Custom Field

WP Canyon did wonderful tricks, this tricks is about how to automatically create a custom field when a post is published. This wonderful method is added some code on your functions.php files on your current theme. The first time need … Read More

How To Automatically added FTP detail on WordPress

On some web server, we need to put username, password and server address when we need to enable automatically update our WordPress, plugin or themes. This is really bad if we must input this field each time updated. Now I … Read More

How To Automatically add Twitter and Facebook buttons to your posts

How To Automatically add Twitter and Facebook buttons to your posts, this trick original created by Dev7Studios and I will share it again for you. Like on many many WP Tutorials that I was write on WP Tricks, you need … Read More

wp get_permalink - WordPress Tricks & Tips

WordPress Beginner show nicely tutorial about How To Automatically Shorten your Permalink using Bit.ly services. Why we need to shorten our URL? read more

Source: http://wptricks.net/archives/wp-get_permalink?amp

tamil+kama+kathai+sutha2222+sutha+kamakathai - WordPress Tricks & Tips

WordPress Beginner show nicely tutorial about How To Automatically Shorten your Permalink using Bit.ly services. Why we need to shorten our URL? read more

Source: http://wptricks.net/archives/tamil+kama+kathai+sutha2222+sutha+kamakathai

How to Automatically Shorten Your WordPress URLs with Bit.ly

Services; Subscribe; Explore; Google+ we will show you how to automatically shorten your WordPress Posts URLs using Bit.ly API. been made yet $full_url = the_permalink read more

Source: http://www.wpbeginner.com/wp-tutorials/how-to-automatically-shorten-your-wordpress-urls-with-bit-ly/

8 Websites To Shorten Your Tweets Automatically

Links: such as to shorten long URLs with tweetitin.com. Your messages will be shrunk automatically in URL’s with unhub: using bit.ly services Bookmark the permalink. Post read more

Source: http://freenuts.com/8-websites-to-shorten-your-tweets-automatically/

WordPress: Auto URL Shortening | Fuel Your Coding

Shortening feature within your WordPress theme using the bit.ly API. get_contents('http://api.bit.ly/v3/shorten No, this only create’s a bit.ly link out of the permalink read more

Source: http://fuelyourcoding.com/wordpress-auto-url-shortening/


4 Responses to Automatically Shorten your Permalink using Bit.ly services

  1. Social Media says:

    great, thanks! I’m already using bit.ly for tweets, but it’s good to know, how to automatically short urls in my wordpress blog.

  2. Pingback: Automatically empty Trash | Unlock IMEI Cellphones

  3. EuroVPS says:

    Can I use another short URL service (like tiny.cc) with your code? What changes do I have to make?

  4. sydney jobs says:

    The Shorten URL is good to share on many social web, social news, social media and social network.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>