Create short URLs on the fly with WordPress
Social media networks like Twitter.com are a fantastic way to share news, information or blog posts. Since every message has a maximum lenght of 140 characters the best way sharing links is with the help of URL shortening services.
This php code adds a “Share this on Twitter” – shortcut to your WordPress site and helps creating short links on the fly.
Open your functions.php and paste this into the file:
function getchilpUrl($url) {
$chilpurl = file_get_contents(“http://chilp.it/api.php?url=”.$url);
return $chilpurl;
}
Paste this into your sidebar.php or wherever you like the link to appear:
<?php
$curl = getchilpUrl(get_permalink($post->ID));
echo ‘<a href=”http://twitter.com/home?status=I liked ‘.$curl.'” target=”_blank”><abbr title=”Share this on Twitter”>Share this on Twitter</abbr></a>’
?>
That’s it! :-)
The link will look like this:
It directs to Twitter and enables one to directly post that shorter link:
Feel free to use this script for developing other ways of integrating Chilp it! URL shortening into your website, blog or application. The script can also easily be changed to support other social networks like Friendfeed or Facebook.
Have fun!
Comments are off for this post