Use TinyUrl In Your ‘Tweet This’ Without A Plugin

April 22, 2009 in Tips & Tricks, Tutorials by Clay/Admin

So I have received a few messages from people asking about how I got my ‘Tweet This’ button below my posts to automatically use TinyUrl instead of the regular URL to help save space on your Tweets. Its pretty straight forward and simple to implement without any need for a plug in!

Enjoy! :)





I actually learned how to do this nice little technique from Humman3rror.com so be sure to go check out his post for a few screen shots!

The first thing you will need to do is go into your functions.php file through your theme editor and add the code below:

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

BEFORE YOU SAVE!!: Double Check All The Quotes! Wordpress likes to screw these babies up so dont  just cut and paste, retype the quotes to cover your ass.

Mine looks like this (go to Human3rror to see his example too):

beyond random e280ba functions Use TinyUrl In Your Tweet This Without A Plugin

Be sure to save the file and then navigate to your single.php file and add the following code to where you want your ‘Tweet This’ to appear.

<?php $turl = getTinyUrl(get_permalink($post->ID)); ?>

<li><a href=’http://twitter.com/home?status=@BeyondRandom <?php echo “.$turl.” ?>’ target=’_blank’>Tweet This Post on Twitter!!!</a></li>


BEFORE YOU SAVE!!: Double Check All The Quotes! Wordpress likes to screw these babies up so dont  just cut and paste, retype the quotes to cover your ass.

I changed what mine would say when someone clicks the Twitter button and linked it to a image rather then text as you can see in the example below (Human3rror’s example)

beyond random e280basingles Use TinyUrl In Your Tweet This Without A Plugin

Now after saving your single.php file you should now have TinyUrl’s made automatically when your image or text is clicked. Below is how it should look when you have it all set:

twitter home 1240427309069 Use TinyUrl In Your Tweet This Without A Plugin

If you have any questions, leave a comment and I will do my best to help you guys out. Big thanks to Human3rror for the great how-to!

Oh and since we are talking about Twitter, go ahead and add me….you know you want to Follow Me!