Twitter Tip: Add a ‘Tweet This’ Link to your Blog on WordPress or Blogger

Written by Amit Agarwal on Mar 17, 2009

tweet thisTwitter 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 (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.

&lt;?php if ( is_single() ) { ?&gt;
&#160;&#160; &lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot; 
&#160;&#160; &lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot; 
&lt;?php } ?&gt;

Step 2: Open the single.php file and insert the following line just below the_content() function.

&lt;a href=&quot;#&quot; onclick=&quot;return, '&lt;?php echo get_permalink();?&gt;');&quot;&gt;   
&lt;span style=&quot;display:none;&quot;&gt;Reading: &lt;?php the_title();?&gt;&lt;/span&gt;Tweet This: Send Page to Twitter&lt;/a&gt;

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.

&lt;b:if cond='data:blog.pageType == &amp;quot;item&amp;quot;'&gt; 
 &lt;script charset='utf-8' src=';amp;login=tweettrackjs&amp;amp;apiKey=R_7e9987b2fd13d7e4e881f9cbb168f523' type='text/javascript'/&gt;  
 &lt;script charset='utf-8' src='' type='text/javascript'/&gt;  
 &lt;a expr:onclick='&amp;quot;return, \&amp;quot;&amp;quot; + data:post.url + &amp;quot;\&amp;quot;);&amp;quot;' href='#'&gt;
 &lt;span style='display:none;'&gt;Reading: &lt;data:post.title/&gt;&lt;/span&gt;Post Link to Twitter&lt;/a&gt;   

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.

Subscribe to our Email Newsletter