‘Tweet This’ Using TinyURL and NO Plugin v2.0

tweetthiswithnopluginv1 Version 1.0 of “Tweet This Without a Plugin” was pretty awesome, but it wasn’t perfect.

You see, I quickly realized that it doesn’t auto-shrink the URL when thrown up into Twitter, which made you lose a lot of valuable tweet space.

So, I set out to create a little code that would auto-TinyURL the permalink without the use of a bloated WordPress plugin (and trust me, the plugins you use for Tweeting your posts is bloated and heavy).

So, instead of the above you get this nicely shrunk link:

tweetthiswithnopluginv2

So here’s how to do it: First you goto your functions.php file and add the following code:

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

Here’s an image of how mine looks:

functionsphp

Then, you goto your single.php file and add the following code inside the content loop:

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

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

The bolded text is what you can change without breaking the function call.

singlephp

Pretty cool, huh? It’s actually quite easy! Gives your blog the “Tweet This” functionality without the additional weight of a plugin.

Nice.

What does mine look like? Just look right below this sentence. Why don’t you hit it for good luck? :)

Filed Under: Technology,Wordpress

21 Responses to “‘Tweet This’ Using TinyURL and NO Plugin v2.0”

  1. allthenations March 4, 2009 at 7:31 PM #

    Thanks for sharing this!

  2. Amanda_Sims March 4, 2009 at 7:42 PM #

    How cool! When I can sit and focus on how to implement this (read: when I'm not crazy-busy at work) I will do it!

  3. russhutto March 4, 2009 at 9:15 PM #

    I'm not a wiz by any means when it comes to this php stuff here's what I'm looking at in my functions.php (courtesy of the simpl3 theme) :)

    <?php
    if ( function_exists('register_sidebar') )
    register_sidebar(array(
    'name' => 'Right Sidebar',
    'before_widget' => '',
    'after_widget' => '',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
    ));
    ?>

    Where might you place it in that bit of code?

  4. human3rror March 4, 2009 at 9:42 PM #

    right before "if".

    • russhutto March 4, 2009 at 10:01 PM #

      Hmm, I keep getting syntax errors.

  5. Bill Whitt March 5, 2009 at 3:28 AM #

    Nice work, man! Love it!

  6. human3rror March 5, 2009 at 5:47 AM #

    doh…!

  7. Phillip Gibb March 5, 2009 at 5:51 AM #

    Nice one. Gonna put that into the blog I am preparing

  8. Jim March 5, 2009 at 4:43 PM #

    sweetness!love learning new ninja tricks

  9. Jim March 5, 2009 at 4:45 PM #

    me likey

  10. Phillip Gibb March 5, 2009 at 4:59 PM #

    ummmmmmmm – u only follow 34 Tweeps?
    that is a lot of self discipline.

  11. djbyron March 5, 2009 at 4:37 PM #

    Awesome… Added this functionality to my blog last night!!

  12. BeyondRandom March 7, 2009 at 10:42 PM #

    WOW! Great idea bro. I never even thought about this before. Im gonna go try this on my blog now. Thanks for sharing!

  13. BeyondRandom March 8, 2009 at 7:09 PM #

    got it working! It took a while because I kept getting some errors. I had to retype the quotes into the code put into the funtctions.php and it worked. Thanks again!

  14. human3rror March 8, 2009 at 8:14 PM #

    SWEET!

  15. Rich Schmidt April 11, 2009 at 4:43 PM #

    Looks like you're not using tinyurl.com anymore, huh? The "Tweet this" link now gives the "ugly WordPress permalink" version: http://human3rror.com/?p=2627. That seems like a better way to go, in my opinion, as long as your domain name is relatively short.

  16. Rich Schmidt April 11, 2009 at 5:05 PM #

    Cool. Seems like a better system to me, since it's built right into WordPress. :)

    Is that why you were tweeting about it earlier?

    • human3rror April 11, 2009 at 5:12 PM #

      i was shooting it over to @michaelhyatt… it was supposed to be a DM…

      uaha.

  17. richard May 10, 2009 at 11:46 AM #

    apMWfR dkv7Rq29nVvzm74lApqSw

  18. Chris Robinson June 18, 2009 at 5:06 AM #

    Thanks man, worked beautifully!

Trackbacks/Pingbacks:

  1. Add Tweet This Without a Plugin! - March 4, 2009

    [...] I’ve created a MUCH BETTER VERSION here. [...]

Leave a Reply: