Stroep

Just a collection of random works – Mark Knol

Tag Archives: twitter

Just a quick but handy tip I’ve found on this post from smashing magazine.

A lot of people who are using twitter, use tinyURL to create very small links for longer URL’s of blogposts or cool links. Its very powerful solution and cost just a little bit time to create, but you can help ‘the twittering people’ by automatically create the tinyURL-link in your post.
Here’s how you can do this in WordPress. It cost less than 2 minutes too implement :)

Just go to design > theme editor > functions.php and add this function

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

Basically you can use this function for every site, but for WordPress it’s handy to use the permalink to create the URL:

In the theme editor > single.php you can add this line where ever you want to show the link to the tidyURL.

<?php  
 $turl = getTinyUrl(get_permalink($post->ID));  
 echo ‘Tiny URL: <a href="’.$turl.‘">’.$turl.‘</a>’;
?>

Tagged with , .