Bin-Blog logoBin-Blog

Learn about the latest in Web Development – as soon as I do.

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

By • Jun 9th, 2009 • Category: PHP, WordPress

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="<?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.


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

6 Responses »

  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 ‘s api recently) I might pounce on you.. 😛 lol

    Good job Binny, there again 🙂

  2. | Balu | says:

    Wow that’s a nice bot of information.. will surely try it out! =)

  3. Ajay says:

    You sure are helping users optimize their WordPress installations 😀

  4. dinu says:

    I use a plugin .. that was easier .. but not sure if that adds additional mysql db load..

  5. Sarmad says:

    how to find the single.php file in the theme? I m using the MOTION theme(wordpress official themes)!! guide me please!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>