Thursday, May 21, 2009

How to : Automatically create TinyUrls for your blog posts

Because of the restriction on character numbers in Twitter, you have to use a URL shortener when tweeting URLs. So, to help your readers tweet about your posts, you should definitely provide short URLs for all of your posts.

Here’s how to automate that task:

Open your functions.php file and paste the following code:

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

Once done, paste this in your single.php file, within the loop:

$turl = getTinyUrl(get_permalink($post->ID));
echo 'Tiny Url for this post: '.$turl.''
?>



To see this in action, visit WpVote, and look at any post.

Source: How to: Automatically provide TinyUrls for your WordPress blog posts

Related Posts by Categories



0 comments:

 

Copyright 2008 All Rights Reserved Revolution Two Lifestyle theme by Brian Gardner Convert by Bloganol dot com Edit by Arieyblog

top