107 How to add "Tweet This" links to your Blogger Template (with short URLs)
Thursday, March 19, 2009 /

Twitter has become one of the most popular ever syndication and networking tools for bloggers. A few readers have asked if it is possible to add a "Tweet This" link to our Blogger templates, and while this was possible, I had not discovered a method of automatically shortening the URL of our blog posts until now.



Luckily for us, Bit.ly have created a JavaScript-based solution which shortens the URL to just a few characters and enables bloggers to add a Tweet This link configured for their posts. In this tutorial, I'll explain how you can add this to your Blogger template so your readers can Tweet your posts to their Twitter followers, enabling your Blogger posts to be syndicated to a wider audience.





Editing your template to add the Twitter links

First of all, you should make a full back-up of your existing template (which you can later restore if you make a mistake in the coding). To do this, go to Layout>Edit HTML in your Blogger dashboard and click on the "Download full template" link near the top of the page. Save your template to a location on your computer which you can easily access later.



Next, go back to the Layout>Edit HTML page and ensure you have checked the "Expand widget templates" box. The place where we need to add the Twitter code is contained within the Blog Posts widget.



Search for this section in your Blogger template code (or similar):



<div class='post-footer-line post-footer-line-1'>


If you cannot find this exact line of code, search for 'post-footer' instead. Alternatively, you can add your code immediately after the <p><data:post.body/></p> line.



Just after the 'post-footer' line you have located, paste the following section of code:



<b:if cond='data:blog.pageType == "item"'><span style='float: left; background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTrKhXkul9jZGgfOz9Dp7RniaP16wPMzI49uUMKqb4m5cgKtVsROYDBfJd1MCrdlRwhOjDhoDaOCmO3TJk6l2DcNagZ6RWoNNAyEriq9H4xESD7StcsjVslBxn1YyAw6NrLgjrsa98Oq3m/s128/twitter-16x16.png) left no-repeat; padding-left: 20px;'><script charset='utf-8' src='http://bit.ly/javascript-api.js?version=latest&amp;login=tweettrackjs&amp;apiKey=R_7e9987b2fd13d7e4e881f9cbb168f523' type='text/javascript'/>

<script charset='utf-8' src='http://s.bit.ly/TweetAndTrack.js?v=1.01' type='text/javascript'/>

<a expr:onclick='"return TweetAndTrack.open(this, \"" + data:post.url + "\");"' href='#'>

<span style='display:none;'>I'm reading: <data:post.title/></span>Tweet this!</a></span></b:if>


Preview the changes to your blog template to make sure you have not made any errors in adding the code. If all is well, the preview page should load (though you will ne unable to see the Twitter link on the preview page).



Finally you can save your template. Now when you view an item page on your blog, you will see a link in the post-footer section which looks like this:



I'm reading: Blogger BusterTweet this!





This link automatically generates a Bit.ly shortened URL for your post. When a reader clicks on this link, they are taken to Twitter.com (where they can log in if required) with a pre-filled Tweet which appears like this:



http://bit.ly/url I'm reading: [title-of-blog-post]


If you would prefer the prefilled Tweet to say something other than "I'm reading", you can edit this phrase in the code you add to your Blogger template. Readers can edit this pre-filled Tweet before updating if required.



I hope you will enjoy using this Twitter syndication link in your own Blogger templates. Please try this out for yourself to see how it works and feel free to leave your comments below.

107 comments:

March 19, 2009 at 5:42 AM Rajeev Edmonds said...

Thanks Amanda,

I was looking for this. This one is the best solution. Thanks

March 19, 2009 at 5:45 AM br3ntbr0 said...

This is rendering an error over not being well formed. It doesn't like the login entity in the first script tag.

March 19, 2009 at 6:03 AM Amanda said...

@br3ntbr0: My apologies, there was a slight error in the code with the ampersands. I've edited this now and checked again by pasting this same code into another of my templates, so all should work just fine now. You may need to refresh the page (f5) to see the changes though!

Hope this helps!

March 19, 2009 at 6:45 AM Drew Kime said...

Thanks for the code. Two questions though.

1) Is there any way to have the URL appear at the end of the tweet instead of the beginning?

2) The link kept wanting to pop up a window. Since I use the popup blocker in Firefox, I got a warning but the page forwarded anyway. Do you know of a way to prevent this?

March 19, 2009 at 6:59 AM CJ Baer said...

Actually, a simpler way to solve this problem is to merely add a third-party code that will connect to any social site you desire. The best I've found are:

http://www.addtoany.com/

http://www.addthis.com/

http://sharethis.com/

March 19, 2009 at 7:00 AM
Radith Prawira said...

is there any ways for getting the url short without any js?

March 19, 2009 at 7:59 AM Vietnamvoiz.com said...

Hi Radith Prawira,

Yes, I have a solution for you. pls visit http://epayvn.info/2009/03/how-to-add-twitthis-to-your-blogger.html for the details.

I hope that this comment would not be deleted by the bloggerbuster administrator so that you can see the url of my post.

March 19, 2009 at 9:05 AM
MJ said...

how abaut js?

March 19, 2009 at 10:34 AM
Radith Prawira said...

@N.P

Hi. Tq. I've left message there. :)

But unfortunately it didn't work for me T_T

--

@Marzuki

JS = Javascript [?]

March 19, 2009 at 11:33 AM cheth said...

Hi Amanda,
This loks great but I guess you would like to suggest @tweetmeme its a lot cooler digg like twitter link.. it shows how many times the post got retweeted.. I'm using it in my blog now :)

March 19, 2009 at 1:55 PM Yoga with Gaileee, E-RYT said...

Hmm,
What if you cannot find any of these things in your html code? What code would you add, to add this section of tweet code?
Thanks!

March 20, 2009 at 2:05 AM Jürgen said...

Danke funktioniert hervorragend !

March 20, 2009 at 7:50 AM CELEBSIMAGE said...

Its a good tool for bloggers.. hehe.

March 20, 2009 at 7:53 AM MUSICVL said...

Ya even if we couldnot use it on our blogger template, we could do it through other social bookmarking tools. And ya even those tools are easy to use. You need not go through all these.
I would prefer any other social bookmarking tools such as add to any or something else.
But even this is great.

March 20, 2009 at 3:26 PM krisu said...

I think that this is much better option, almost same, but less code and don't use any popup...

http://i-stuff.blogspot.com/2009/02/add-tweetthis-button-your-blog.html

March 20, 2009 at 7:49 PM MandM said...

This is fantastic Amanda! I am stoked to find this as I hated Twit This as it required people to log in each time and every other option either didn't allow for text - I changed your code to make the text include reference to my blog - or had monster urls.

The only thing I would ask is the same thing as Drew Kime above: Is there any way to have the URL appear at the end of the tweet instead of the beginning? (my code knowledge is very limited and I couldn't work that one out)

March 20, 2009 at 7:57 PM MandM said...

Cheth @tweetmeme looks cool, love the fact it counts the retweets, but the instructions as to how to install it are vague "Copy and paste the following code where you want the widget to be displayed."

It assumes knowledge of code that I don't have.

And when I have tried it it tweets my home page not the page specific to the blog entry being retweeted. Amanda's is much better and I can set up a search via tweetdeck to track any retweet's based off the extra text I added to her code that named my blog.

March 20, 2009 at 8:41 PM oom gendut said...

i have trouble with this :

error XML: The reference to entity "login" must end with the ';' delimiter."

please help me :)

March 21, 2009 at 1:29 AM Muhammad Yaqoob said...

I did it but the twitter icon and link is not showing in my blog. what to do?
i need help.

March 21, 2009 at 9:46 AM Shin Okada said...

It works with FF but not with Chrome.

March 21, 2009 at 2:34 PM JustinSMV said...

Thanks Amanda, great code to add to help get your posts exposure on Twitter

March 21, 2009 at 7:47 PM Gunawan said...

thanks Amanda...
i already use twitter... (http://twitter.com/citraglobal)
thanks for share..

March 22, 2009 at 3:25 AM watzabatza said...

Wow! Thanks for this. I found it here.

March 22, 2009 at 3:53 AM Ching Ya said...

Thanks Amanda for the sharing, I was inserting manually tweet this post before this, which is why I'm so glad I found your post.

However, I do find that IE was unable to display this after I added in after footer @ body-post; even refreshed couple of times as suggested. Based on the commenters above, could it be only IE's viewing problem?

Thanks in advance.

@wchingya
-Social network/blogging

March 22, 2009 at 8:15 AM A.Jaye said...

I added the code to my blog

http://thrillfiction2009.blogspot.com/

And saw no change whatsoever. I went through firefox and viewed through that and ie8. Same difference. I am green to all of this but help! Please.

March 22, 2009 at 11:21 AM kandi111777 said...

Thank you to krisu. The code above wouldn't work for me for some reason; however, the code that krisu linked to worked for my blog. I appreciate that the blog owner did not delete the post and I thank everybody for their help. You can check it out here: www.kandiandkeith.com/blog/index.html. Thanks!

March 22, 2009 at 12:38 PM bisnisway said...

wow..i will use this....

March 22, 2009 at 10:47 PM nady said...

amanda check u blog whit IE7 (error)...page cut off

March 24, 2009 at 12:02 AM ADMIN said...

@MandM

Amanda's code is cool I used the same thing few months back.. but turst me @tweetmeme is easy, I would be able to help you to install it.. yea you can track this via @tweetdeck as well..

March 24, 2009 at 8:34 PM Tech Blogger said...

Hi Amanda,

This was quiet simple to drag & drop in the HTML code section and useful trick for both sides :

1 case- You want to choose a post and tweet it up in your twitter profile.
2 case- or someone would tweet it up on his own twitter profile.

It's still great if you would select only specific posts and tweet them. I actually update my twitter automaticly from my blog so any new article i post it's showing up on my twitter.

So, anyway!! thanks for posting this.

March 25, 2009 at 2:33 PM The Fitness Diva said...

This one rocks, Amanda! I'm definitely liking the 'tweet this' option! :)

March 26, 2009 at 5:55 AM Admin said...

I have added the code where you said it should be added , yet I do not see any button at all could you please help ...

March 27, 2009 at 4:18 AM Sandeep Rohilla said...

Hi, i used ur template cool_blue, everything is fine but when any one try to put comment then it doesnt show me box like before it also not show any reaction button please help me to short out the problem ...
www.solutionatoz.blogspot.com (blog)
gogosandeep85@yahoo.com email id
plese send me reply or inform me how to resolve it

March 27, 2009 at 4:02 PM
Andrew said...

Hey Amanda, please, please respond. When i try to put an html code on my website, it just shows up as what im giving the html for. So since you are using blogger, how do you put the html out without it changing to a link or widget? Once again please, please respond, I know alot of people who want to know this. Thank you.

March 28, 2009 at 7:49 AM Xpresi Blogger said...

Wew.. I'm going to use it but, first of all I have to register...

March 28, 2009 at 8:13 AM Eva Lyford said...

excellent write up! I added this to my site today. I had to make one minor addition by adding br / enclosed by angle braces to get it to be unsquished against my timestamp. Thanks for the code snippet!

March 28, 2009 at 4:40 PM yarnpiggy said...

I had some problems getting it where I wanted (it wants to butt up against "Posted by yarnpiggy" rather than on a line above it), so I did some totally crappy hacking of the hack; it's still not perfect, but it gets the job done. Thanks!

April 1, 2009 at 1:15 AM future mantra said...

Nice blog. Only the willingness to debate and respect each other’s views keeps the spirit of democracy and freedom alive. Keep up the good work. Hey, by the way, do you mind taking a look at this new website www.indianewsupdates.com . It has various interesting sections. You can also participate in the OPINION POLL in this website.

Kindly note: The comments section is having problems so you may not be able to comment right now but it will available in a few days. We are also planning to get Live Cricket in our website within this week.

Dear friend, if you have any suggestions or information or news which you think has been ignored by the mainstream media, kindly let us know. We will try to implement that in our website.

Kindly go through the entire website. Who knows, it might just have the right kind of stuff that you are looking for. If you like this website, can you please recommend it to at least 5 of your friends. Your little help would help us in a big way.

Thank you,

The Future Mantra

April 1, 2009 at 10:12 AM Internet Marketing Traffic said...

i will add twitter on my blog. Hopefully, my traffic would increase significantly.

April 1, 2009 at 5:06 PM The First Carol said...

How do I reverse it?

Here's the order I have:
http://bit.ly/nlVPg I'm reading: Asians in art

Here's the order I want:
I'm reading: Asians in art | http://bit.ly/nlVPg

April 3, 2009 at 1:46 AM Gerri said...

Worked a treat. Thank you so much for this.

April 3, 2009 at 3:05 PM
Nambahu said...

The button really is cool. too bad I could not locate the post-footer code in my template.

April 4, 2009 at 1:28 PM
Jabber said...

why no recent updates !!

April 4, 2009 at 11:54 PM Misha said...

Hi,

Is there anyway to have this so it shows up on each post on my home page (so readers don't have to visit individual posts to Tweet it)?

April 6, 2009 at 2:24 AM limferdi said...

hi I'm limferdi one of the avid readers of your blog, I get to learn many things here and I even applied some of your tips on my blog. Pls add me to your blog roll and I'll add you up to my new blog it's http://limferdi-nest.blogspot.com thank you

April 6, 2009 at 7:28 AM jiggoo.com said...

nice work done amanda!
this is really working

April 6, 2009 at 12:51 PM Melvin said...

Excellent! Thanks..

Nice site, by the way!

Melvin Durable
melvindurable@gmail.com

April 8, 2009 at 7:43 AM SmartComputerTips said...

Yes...i like your theme. Very nice share. thanks anyway.

April 9, 2009 at 12:07 PM RAJEEV said...

Nice article .. http://moneyforinvestment.blogspot.com

April 9, 2009 at 12:08 PM RAJEEV SINGH said...

Nice article.. thanks

April 11, 2009 at 7:29 AM GigiSehatBadanSehat said...

thnk u amanda....
and i vote your blog to in Bloggers choice award 09

April 12, 2009 at 7:52 AM nazz said...

thanks Amanda, but it seems not working in my blog..

April 13, 2009 at 9:50 PM gamezined said...

thx amanda, i like your blog.. and your posting too

April 13, 2009 at 11:32 PM romeobust said...

when i open this blog, i found something 4 my blog.....thanx amanda...ur the best

April 14, 2009 at 9:39 AM
Carolyn said...

Hi Amanda :)

Thank you. This is wonderful. I tried adding it to my main blog, but I couldn't get it to work. It shows, but when you click, it just redirects to the blog again. Perhaps because I still use the classic blogger template? (emailed you too)

April 14, 2009 at 2:59 PM Kyle/thebookpolice said...

These links only show up when you're viewing a specific post. When you're on the main page of my blog, for example, you don't see the Tweet This link. Click into any specific post, however, and it's there. Is there a way to get it to appear on the main page as well?

April 16, 2009 at 1:41 PM Lynda Lehmann said...

Amanda, you always have something good and useful for us! I will always recommend your blog for tips and tools and reliable information!

April 16, 2009 at 4:12 PM
Hakim said...

Thanks,

Worked great!

http://optionsincomereport.blogspot.com/

April 19, 2009 at 6:00 PM Jenna said...

Hmmmm, I added the code to www.loveofbabyonline.com but no changes. :(

April 21, 2009 at 4:47 AM Fabulous Photo Gifts said...

Hi - thanks - works a treat. I added it to:

http://www.home-improvement-blog.co.uk and

http://purple13.blogspot.com (personalised photo gifts) blog.

The 'Tweet this' and icon appear in the footer when you click on an individual post to read it, rather than under each post when you're looking at the overall blogs 'home page', if that helps anybody above whose added the code but can't see the link appearing.

Thanks for your help with this.

Good luck everyone else and hopefully see you over on Twitter? - http://twitter.com/fabphotogifts

April 21, 2009 at 5:10 AM Fabulous Photo Gifts said...

Hi - Just wanted to add a little clarification to my earlier remark about anybody using this but thinking it isn't working.

The Tweet this (& logo) only appears when you click on an individual story / article as it takes this information to create a link to that article.

The alternative is to put a 'Tweet this' link on your sidebar of your main blog and allow people to tweet the blog url rather than the post url.

Depends how focused you want to make the sharing.

Jonathan

April 23, 2009 at 4:12 AM Jonathan Crouch said...

Hi Amanda

Thanks for that - the code worked a treat (or should I say 'tweet').

I've added it to two blogs - one is for Fabulous Photo Gifts - http://purple13.blogspot.com, the other is on a home improvement quotes blog - http://www.home-improvement-blog.co.uk.

To give the words 'tweet this' a little space, after the logo, I added a
before the words Tweet this.

One question - I tried changing the image for another (replacing the image src link) but assume your javascript has something in it that leaves a 16x16 pixel space as the spacing went all wrong?

Be nice to hear back from you on that one.

To anyone else above struggling - just re-check you're entering the block in the right place, watch out you're not copying and pasting and missing an open or end bracket.

Also, as i see it, this script has to only appear when you open the actual article in its own window as it looks like it takes its title for the shortened url from that page title.

Regards
Jonathan

Twitter - http://twitter.com/fabphotogifts

April 24, 2009 at 1:17 AM Vijay said...

Thanks a Ton Buddy !!

I just implemented this on my blog(www.msigeek.com)and it works like a charm.

April 26, 2009 at 9:41 AM Alan said...

Hi Amanda,

I did it in 5 minutes and it worked and I'm using the JS-Kits commenting system.

April 26, 2009 at 12:38 PM Alan said...

It took me only 5 minutes to add it to my js-kit commenting system blogger...Easy!

Thanks

April 27, 2009 at 6:15 PM Lady D said...

Hi---great code thanks! The only issue is- you cant see it on the main page, only when you go into the post. Any updates for this prob yet? Thanks!

April 30, 2009 at 10:44 AM Sophie Lhoste said...

this is not working on my blog

May 3, 2009 at 3:12 PM Andy said...

Just wanted to say thank you, so thank yoy

May 6, 2009 at 3:56 AM العاب شمس said...

Very helpful tools for blogger, thanks.

May 12, 2009 at 2:17 PM Diana said...

Thank You Amanda..nice :-)

May 17, 2009 at 4:13 PM rigo said...

Thanks amanda!

Regards from costa rica.

May 20, 2009 at 8:46 AM Kris said...

This is great! Is there a way to get it to show up at the bottom of a post from the main blog page? Right now a reader has to click on the post itself to see the "tweet this" option.

Thanks!

May 21, 2009 at 5:33 AM Lauren said...

Thanks for all your help! This is a great site, your tutorials have been of much assistance to me setting up my blog.

May 24, 2009 at 5:29 PM
Anonymous said...

Glad you posted this.

You might think about not having ads play sounds automatically on your blog.

June 6, 2009 at 4:53 PM Favors With Love said...

Thanks so much! Just added it to the Favors With Love blog! Awesome!

June 16, 2009 at 1:24 AM TOPNews said...

thank amanda...

i will take it,,

great article
th u v much

June 21, 2009 at 11:55 AM JH said...

Is there any change to show number of tweets per post?

Like similar WP-plugin is doing.

June 24, 2009 at 10:14 AM Abi said...

Thanks for sharing this. I was looking to have this link with URL shortening feature and you have provided one.

Thanks!

June 28, 2009 at 10:00 AM usmc81@gmail.com said...

Thank you. Works great (after I removed the IF tag).

June 29, 2009 at 7:38 AM ONLY IN THE PHILIPPINES said...

It's an amazing trick.Thanks a lot!

July 2, 2009 at 1:06 PM Cerulean Bill said...

It's not working for me, which I'm guessing means I'm being dumb about something. I inserted the code after the ".post footer {" section, between its closing curly brace and the next section - ".post-footer .post-timestamp," . I don't get anything indicating tweet-ability on the displayed page. I also tried inserting the lines on the next physical line after that opening curly brace (ie,the code was insserted as the very first thing within the curly braces) ; also nothing. Can you suggest what I might be doing wrong?

Thank you.

July 6, 2009 at 5:22 PM Gina @ MoneywiseMoms said...

It looks like this works only when viewing a specific page post by permalink. Is there something I can use to have the "Tweet This" show up when you're just scrolling through the whole site?

July 8, 2009 at 8:33 AM bella said...

This did not work for me at all and I tried several times inserting it....what am I doing wrong because I REALLY, REALLY want to add the "Twit This" option to my blog posts. I hope to hear from you (or someone) please!

July 15, 2009 at 9:25 PM
Brian said...

This doesn't seem to be working on my blog (http://scrubsandpubs.blogspot.com). Help? I'm trying to do this with the code for the ShareThis button too.

July 17, 2009 at 8:53 PM roxy said...

Thank you! removed the IF tag and this works like a charm.

July 24, 2009 at 10:27 AM Kat said...

Thanks very much! Very helpful

www.lostinparis.co.uk

July 26, 2009 at 2:19 PM Coupon Lady said...

I just added this to the site and it was easy. The one of few times something worked the first time. Thanks for the help!

August 4, 2009 at 7:14 AM Gil Bouhnick said...

Thanks for the tip.
I managed to embed the badge to my posts, hopefully people will start tweeting my articles!

MobileSpoon

August 11, 2009 at 7:32 AM Pink Diamond said...

Cool! Thanks for the tips. I've already added it on my blog.

http://justmypersonalopinions.blogspot.com

August 12, 2009 at 9:23 PM Leif Hanlen said...

I've just added this to my site: wearable-intelligence.blogspot.com BUT, I removed the first IF statement. ie, it now reads

(b)(span ...)
everything as it was
(/span)(/b)

where I'm using parenthesis instead of angles so the post doesn't turn into HTML.



This seems to work -- so I get a tweet this on the front main page for every post, and don't have to click on teh post first (as noted by the posts above..

and the tweet activates in the same browser window (although it tries to open a new window). My firefox has pop-ups off, so I don't actually see the pop-result.

Amanda: any thoughts how to stop the pop?

August 17, 2009 at 4:49 AM Verena said...

hello, I added it and it works -no big deal. It's shown at the end of a post. Thank you!

August 23, 2009 at 11:27 PM Sonshine Chavous said...

My eyes hurt from looking up ways to do this...THANKS!!!

August 24, 2009 at 4:49 AM shvtrix said...

does any other url shortening service provide this feature

August 26, 2009 at 3:11 PM Ongezout said...

what if you wanna add more social bookmarks (with own picture) under each post ? I'm looking around for this script but no luck so far. I have some cool bookmark icons I wanna use under each post with correct link without having to copy paste everytime the exact link when I post a new message.

hope you guys can help.

greetings

September 12, 2009 at 10:11 AM
Moderator said...

Simple and brilliant.
I will add it to Yourblogsite.com soon

September 16, 2009 at 7:30 AM
Anonymous said...

What about for those of us who still use classic blogger templates?

September 20, 2009 at 3:50 AM Night Time Brothers said...

This code didn't work on our blog, but http://sharethis.com/ certainly did!

You can check how share this looks like on our site: http://nighttimebrothers.blogspot.com/

September 22, 2009 at 4:53 AM djWhite said...

You're so goooood! Thanks for the how-to!

Post a Comment