Twitter can be a great source of traffic for your blog. To give you an example, my article on bookmarklets was on the delicious popular section for more than a day yet Twitter sent in more visitors than delicious thanks to all the tweets.
Now if you want to make it easy for your site visitors to share links of your blog articles on Twitter, follow the instructions below – you don’t need any plug-ins and the post URLs are automatically shortened in the tweet via bit.ly (a good alternative to tinyurl that also provides live traffic statistics).
Add Tweet This to your WordPress Theme
Step 1: Open the header.php file of WordPress and insert the following lines just before the closing </HEAD> tag.
<?php if ( is_single() ) { ?>
<script type="text/javascript" charset="utf-8"
src="http://bit.ly/javascript-api.js?version=latest&login=tweettrackjs&apiKey=R_7e9987b2fd13d7e4e881f9cbb168f523"></script>
<script type="text/javascript" charset="utf-8"
src="http://s.bit.ly/TweetAndTrack.js?v=1.01"></script>
<?php } ?>
Step 2: Open the single.php file and insert the following line just below the_content() function.
<a href="#" onclick="return TweetAndTrack.open(this, '<?php echo get_permalink();?>');"> <span style="display:none;">Reading: <?php the_title();?></span>Tweet This: Send Page to Twitter</a>
There’s a similar service called TwitThis which is again easy to setup but it requires the Twitter password so some of your readers may not feel very comfortable doing that.
Add Twitter to Blogger Template
Go to your Blog Layout -> Edit HTML and click the box that says "Expand widget templates".
Take a backup of your Blogger template. Now search for the class "post-footer" in the Blogger XML template and copy-paste the following snippet somewhere near that class.
<b:if cond='data:blog.pageType == "item"'> <script charset='utf-8' src='http://bit.ly/javascript-api.js?version=latest&login=tweettrackjs&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;'>Reading: <data:post.title/></span>Post Link to Twitter</a> </b:if>
That’s it. If you want to replace the “Tweet This” link with a graphic of the Twitter bird, add an IMG tag instead of text. For more Twitter tricks, check the Twitter Guide.
Find this article at: http://www.labnol.org/internet/twitter-links-for-wordpress-and-blogger/7995/
Reader Comments
No use if using Adsense, social traffic is ‘bad’ for Adsense! Dont you agree, only organic search traffic is good for Adsense, if no Adsense than its fine : )
Written by Piyush on 03.17.09
Is there any way to change the Twitter this text to some kind of a twitter favicon instead?
Written by Davis Freeberg on 03.17.09
Thanks Amit for this tip.
Written by Subi on 03.17.09
the class “post-footer” in the Blogger may be confusing for some users. Because some may have css classes with “post-footer” name. Better to say it as <div class=’post-footer’>
Written by Debiprasad on 03.17.09
This one is really good, I’ve recently written for PHP implementation under wordpress for the similar scenario including bit.ly JSON (Via PHP) and tinyurl on the fly url shortening.
What I’ve learned from here is the javascript implementation of it.
Great :)
Written by Ruhani Rabin on 03.17.09
Nice info. Nowadays the twitt thing is becoming very famous. I am adding into my blog aswell. Thank for the tips amit.
Written by Krishna on 03.17.09
@Davis Freeberg
Replace Post Link to Twitter to html of image.
As example <img src=”[images-path]/twitter.png” border=”0″ />
Replace [images-path] with your original image path. (I assumed image file name as twitter.png, which may vary at your case.
Written by Debiprasad on 03.17.09
I am using Blogger. I was unclear about how you would use the Twitter Bird instead of text. Would you explain in more detail?
Written by Charli Jessup on 03.17.09
@ Charli Jessup
Hope u have seen “Post Link to Twitter” in the BLOGGER CODE.
Please replace that with “”
this will show the picture that u included in the anatomy… post
so u download the bird pic from any site and upload to blogger and u will get the image src link. give that link instead of link
Written by eplmatches on 03.19.09
I have this working, but it only shows up in single-post view. Is there a way to get it to show in the posts on the home page? If you look at my blog, link , you can see the other sharing icons there, but not this.
Written by Ill in Illinois on 03.20.09
Hi Amit. I’ve insert this script into my website. It’s work. Thanks.
Written by Agung Setiady on 03.30.09
any sign of a “tweet this” for wordpress.com blogs?
Written by Tim B on 03.31.09
On my Wordpress blog, this successfully opens a window with my twitter home page, but there is no shortened URL filled in as you seem to promise. What did I miss?
Written by Mark Traphagen on 04.01.09
It looks like Wordpress.com users now have a twitter widget but so far no “tweet this”. I’ve added the widget but keep getting a message saying “can’t connect to twitter” which is a problem!
Written by Tim B on 04.02.09