A Tweet This Button for Each Post in WordPress – Without a Plugin

WordPress Metal Logo

TweetThis is a WordPress Plugin that ‘adds a Twitter link to every post and page, so your readers can share your blog entries on their Twitter accounts with ease.’ And in the tradition of my WordPress Plugin Killer Series, this post will show you how to do it without a plugin.

The Code

You can add twitter button to your post by editing the single.php file in your theme. Go to the place in the file where you want the button to show up – then add this code at that location…

<a href="http://twitter.com/?status=<?php echo urlencode(the_title('','', false)) ?>+-+<?php the_permalink() ?>">Tweet This</a>

This is a super simple way of doing it – with a little more code, you can use a URL shortner to ‘shortify’ your permalink. Otherwise it might overflow the 140 char limit.

Twitter

By the way, if you are on twitter, add me – I’m @binnyva

6 Comments

  1. I think most of them would need a url shortner, hmm I would need anyway. My permalinks are kilometres long.. lol

    This vacation I am gonna kill most of my plugins, will add this one too.. If I cant integrate the url thingy (I learnt the u.nu ‘s api recently) I might pounce on you.. 😛 lol

    Good job Binny, there again 🙂

Comments are closed.