So Twitter has a cool new tweet button you can add to your blog. I’m sure there’s a bunch of plugins you could use to add it, like this one for example, but most times I prefer to add this sort of thing without a plugin. Here’s what I did to add the Twitter tweet button to my Thesis site:
Step 1: Generate your Twitter tweet button code
Visit the Twitter Tweet Button code generator on Twitter. Customize it how you’d like and simply grab the code.
Step 2: Add the code to your custom functions file
Using Thesis hooks, we’re going to add the tweet button code to the top of every post. So, this is just where I chose to put the button. Of course, you should decide where you want it and use the applicable Thesis hook. Add this code to your custom-functions.php file:
function tweet_button() {
if (is_single()) { ?>
<div class="tweet-button">
<!--ADD YOUR CODE HERE-->
</div><!--end tweet-button-->
<?php } else { }
}
add_action('thesis_hook_before_headline','tweet_button');
Paste in the code you copied from the Twitter site where it says “Add your code here.” Note that the way I have this coded is that the button will only show up on single posts, not on actual pages. It wouldn’t make sense to tweet a contact page for example. If your requirements are different, you’d just have to modify the code so the button shows up where you want. Just use WordPress conditional tags for your needs.
Step 3: Add the CSS
I wrapped the code in a div with a class of “tweet-button”. This is so that I could float the button to the right, or position/style it how I want. Again, you should add your own positioning based on where you want it in your theme. This is just the way I did it, and a starting point for you to customize it. Add this to your custom.css file:
.custom .tweet-button { float:right; margin:0 0 0 15px; }
That’s it!
Pretty simple. Now click the button and tweet this post!
Was this post helpful? Consider subscribing to my blog via RSS or







































{ 14 comments… read them below or add one }
The twitter buttons are absolutely fabulous. I like this tutorial – a much needed one. I have been using tweetmeme, I think it would be a good idea to switch over directly to twitter’s buttons.
Dr. Lawrence Kindo recently posted..Why I Decided to Enter a Blogging Contest
Thanks for sharing your custom function which enabled me to do that which other functions’ codes failed. Appreciated!
What does it mean, though, if I click the tweet button and send a tweet, the box count says 1, I refresh the page, and the count goes back to 0?
Ari Herzog recently posted..Help Me Find My Next Job
Hi Ari… thanks for commenting. The only reason I can think of that the twitter counter will get reset to zero, may have something to do with the permalink of the post. I believe the script counts the tweets based on the permalink URL. If that changes between tweets, it will not pick up the previous count. Not sure if you did anything along these lines.
Dear,
I have tried the code but I never displayed the Twitter… I’m looking for 2 weeks now how to put the FB Like + Twitter Official like you (close to the title on my Thesis).
Your help will be more than mandatory!
Many thanks in advance,
Christophe
Fixed
its working, but tweetmeme plugin is easy to use.
Dj Trinity recently posted..Behringer BCD2000 review & Mapper for Virtual DJ 60
How can I put the buttons to float/align to the right of the headline?
Thanks for commenting. Did you try Step 3 above? That will float the button to the right.
Yeah I was able to pull it through. The problem I had is that I was trying to add 4 buttons. But I managed to pull through it.
this’s cool.. thank so much for your share. it so help me to desaign.
hey guys,
i have a problem with custom.css, everthing i add in this file don’t work like don t have permision..what can be?
Sorin recently posted..Am iubit, mesaje pentru iubit
In Thesis site options, make sure the custom stylesheet option is enabled.
what if I want to implement this on my home page only, not on a single post page
jayson recently posted..Interview with Mike Essex of Koozai – The Art of Giving Away Free Stuff
Change
'is_single'in the code to'is_home'.