Smashing Magazine - we smash you with the information that will make your life easier. really.
Introducing Tweetbacks Plugin for Wordpress
Just yesterday we introduced Twitter Avatars In Comments plugin for Wordpress that enables bloggers to have both Twitter and Gravatar avatars in blog comments. We are certainly not going to turn Smashing Magazine into a repository of Twitter plugins for Wordpress, but we are confident that it does make sense to introduce another plugin that enables another kind of Twitter integration in blogs.
This is why this post releases the Twittbacks WordPress Plugin that was developed and released especially for Smashing Magazine — this plugin imports tweets about your posts as comments. You can display them in between the other comments on your blog, or display them separately.
Advantages of our implementation
This implementation is inspired by Dan Zarrella’s great work on TweetBacks. Although his implementation does what it promises, we felt that it could be done in another way and offer users an alternative to display tweets in a more convenient way.
Dan’s solution uses JavaScript, which will work on more platforms, but we felt that it would be useful to actually store the tweets in the database instead of using JavaScript to display them. Because our implementation stores Tweets in the database, you can create new plugins that use this data on the top of our plugin.
Besides, our implemenation does not does not require JavaScript and requires significantly less time to load (server-side, not client-side). (Because we know you want to test this, and be able to ditch the plugin if you don’t like it, we’ve added an uninstall function, which will delete all the stored tweets from your WordPress database.)
Installation
The installation couldn’t be simpler:
- download the plugin from Joost de Valk’s release post,
- copy the “
tweetbacks” folder to your plugin folder (wp_root/wp-content/plugins); - login inside your WordPress administrator panel and activate this plugin (Click “Plugins” and then “Activate” near to the plugin title);
- if you are using Wordpress 2.7, just add the code presented in the next section of this post (Styling and Adding Tweetbacks in Wordpress 2.7) and you are done.
- otherwise if you are using older versions of Wordpress, you can add Twitterbacks similarly to the way it is presented in this tutorial:
- Access your
comments.phpfile and locate the following code:<?php foreach ($comments as $comment) : ?>
Immediately after the above code, place this code:
<?php $comment_type = get_comment_type(); if($comment_type == 'comment') { ?> - Next, scroll down a little bit and locate the following code:
<?php endforeach; /* end for each comment */ ?>
Put the following code right before the above code:
<?php } /* End of is_comment statement */ ?>
This will filter out all of the tweetbacks, trackbacks and pingbacks from your main comments loop. Now we need to create a second comments loop to display tweetbacks, and a third loop to display the trackbacks and pingbacks.
- Right under the code from step 2 you should find this code:
<?php else : // this is displayed if there are no comments so far ?>
Put the following code right before the above code:
<h3>Tweetbacks</h3> <ol> <?php foreach ($comments as $comment) : ?> <?php $comment_type = get_comment_type(); ?> <?php if($comment_type == 'tweetback') { ?> <li><?php comment_author_link() ?>: <?php comment_text() ?></li> <?php } ?> <?php endforeach; ?>Followed by this:
<h3>Trackbacks</h3> <ol> <?php foreach ($comments as $comment) : ?> <?php $comment_type = get_comment_type(); ?> <?php if($comment_type != 'comment' && $comment_type != 'tweetback') { ?> <li><?php comment_author_link() ?></li> <?php } ?> <?php endforeach; ?> </ol> - And you are done.
- Access your
Styling and Adding Tweetbacks in Wordpress 2.7
As the plugin will import these tweets into your comments, they will by default be shown as normal comments on your blog. They will get the class tweetback. If you’re using WordPress 2.7 and the default theme, or any other theme that has taken the styling from the comments from the default theme (which is a sensible thing to do), you could style these tweetbacks by adding something like this to your stylesheet:
pre class=”brush: css;”
.commentlist li.tweetback {
background-color: #94E4E8;
}
If you want to display them separately, you'll have to separate your comments, pingbacks and tweetbacks from each other. A great tutorial on how to do that is Separating Pings from Comments in WordPress 2.7.
After you've done that, you can add the following code to display the tweetbacks:
if ( !empty($comments_by_type['tweetback']) ) :?>
<h2 id="tweetbacks"><?php echo count($comments_by_type['tweetback']);?> Tweetbacks to “<?php the_title(); ?>”</h2>
<ul class="commentslist tweets">
<?php wp_list_comments('type=tweetback'); ?>
</ul>
<?php
endif;
If you want to give that list of tweetbacks a different look and feel, you can add a callback to the wp_list_comments call above. The callback could make them look like this, for instance:

The code for the callback used above looks like this:
function yoast_list_tweetbacks($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
$avatarurl = str_replace("twitter:","http://s3.amazonaws.com/twitter_production/profile_images/",$comment->comment_author_email);
?>
<li class="tweetback" id="comment-<?php comment_ID(); ?>">
<div id="div-comment-<?php comment_ID(); ?>">
<div class="comment-author vcard">
<img alt='' src='<?php echo $avatarurl ?>' class='avatar avatar-40 photo avatar-default' height='40' width='40' />
<cite class="fn"><a href="<?php echo $comment->comment_author_url; ?>" rel='external nofollow' class='url'><?php comment_author(); ?></a></cite> <span class="says">says:</span>
</div>
<div class="comment-meta commentmetadata"><a href="#comment-<?php comment_ID(); ?>"><?php comment_date('F jS, Y'); ?> at <?php comment_date('H:i:s'); ?></a></div>
<p><?php comment_text(); ?></p>
</div>
</li>
<?php }
Because these tweetbacks are stored as comments in your database, you can all sorts of cool things with them. Improving the Web has written a Widget pack that will work with this plugin, called Tweet Stats. It allows you to add widgets with "Recently tweeted posts" and "Most tweeted posts" (see examples below).

If you have any installation problems, questions or suggestions for this plugin, please either comment on this post or add your suggestions in the support forum on Wordpress.org.
About the author
The plugin was developed by Joost de Valk, a Dutch geek and WordPress developer. You can follow him on Twitter.
The team here at Smashing Magazine. Mostly Sven & Vitaly.
- 115 Comments
- 1
- 2January 9th, 2009 4:16 am
Great plugin, definetly worth integrating if you are tweeting your latest blogs and articles around!
- 3January 9th, 2009 4:18 am
Nice! Very useful, I will be adding this to The Dude, just finished applying the wordpress hacks from your other post that are useful to me too!
Smashing Magazine u are legends :)
- 4January 9th, 2009 4:21 am
That’s great!
Thanks SM! - 5January 9th, 2009 4:39 am
Very nice. Can’t wait to try it out.
- 6
- 7January 9th, 2009 5:35 am
You guys a really putting out quality stuff here!
- 8January 9th, 2009 5:55 am
Congratulations for the great plugin!
Best Regards
- 9January 9th, 2009 6:09 am
Very useful little thing! Keep it up!
Thanks!
- 10January 9th, 2009 6:12 am
Wait, how do other people going about a “Tweetback”? What does their twitter msg need in it?
- 11January 9th, 2009 6:58 am
Awesome app, great job Dan! FYI, TweetBacks has a new logo; much nicer than the one in this post.
- 12January 9th, 2009 7:30 am
Appears not to work with intensedebate. Am I right?
- 13January 9th, 2009 7:39 am
Nathan, their tweet needs a link to the post in it, from a supported shorturl provider. The plugin currently supports tinyurl, is.gd, bit.ly, snipr, snurl, snipurl, tr.im,adjix, advu & zima.
- 14January 9th, 2009 7:44 am
Thanks… TwitterTools is out the window since it doesnt accounce new posts in a shortened url like tinyurl
- 15January 9th, 2009 8:00 am
Thanks for all the kind words! Be sure to follow me on twitter to get the latest updates on the plugin!
- 16January 9th, 2009 8:48 am
That’s awesome ! Thank you for filling your spare time to create this for all of us :)
- 17January 9th, 2009 9:23 am
Another nice tweetback plugin … released yesterday ;)
will be found under:
- 18January 9th, 2009 10:42 am
Hmm…, have it installed but tweetback class isn’t showing up. Could be my theme maybe?
- 19January 9th, 2009 11:46 am
Very nice plugin. Will for sure be using this sucker!
- 20January 9th, 2009 12:53 pm
this is a badass widget. instant classic.
- 21January 9th, 2009 1:33 pm
For everyone who has issues implementing the code for below 2.7 blogs: it should be
== "tweetback", not= "tweetback", and for the trackbacks it should be!= 'comment' && != 'tweetback'instead of just!= 'comment'. - 22January 9th, 2009 2:02 pm
Got this up and running on my blog. Is it possible to block your own Tweets from appearing in your Tweetbacks?
- 23January 9th, 2009 2:09 pm
Iain Broome not yet, but that’s a great idea!
- 24January 9th, 2009 2:25 pm
Oh yeah Yoast.com is looking good! Will put this up on my very first WordPress theme design on my website! Thanks for sharing! ;)
- 25January 9th, 2009 2:37 pm
Works wonderfully – thanks Joost :D
- 27January 9th, 2009 4:41 pm
Can´t make it work with the Revolution theme. I can se that somebody has tweeted in the sidebar for the widget latest comments. I can see that there has been a comment (tweet) left in the commentsection, but I cant´t see the comment (tweet) itself.
What to do?
Thanks! - 28January 9th, 2009 5:54 pm
Would like to thank Joost as he helped me get things rocking nicely with this plugin at my site (onemanlab.com). Really a great tool, lots of potential.
- 29January 9th, 2009 7:06 pm
Nice. I will be adding this into my sites over the next couple days. Thank you for releasing this.
- 30January 9th, 2009 9:40 pm
very nice i’ll add to my blog.
thanks
- 31January 10th, 2009 1:29 am
Very cool – I like being able to have tweets integrated with comments. Would love to be able to filter my tweets out – looking forward to that addition!
In the meantime (for WP 2.7) can we delete our own tweets by moderating those particular comments?
Thanks for a great plugin!
- 32January 10th, 2009 2:13 am
Thx for all your help in reaching Digg front page!
- 33January 10th, 2009 3:13 am
Let’s have the same for an open microblogging network such as Identi.ca’s Laconi.ca !
- 34January 10th, 2009 4:14 am
Hi! Thanks for a great plugin!
Just a little idea for improvement:
Many people have a registered webpage on their twitter-profile. What if the plugin could allow the link in the tweetback to point to the webpage of the author, in stead of the tweet itself? I think that would be more useful than todays’ solution.It could also be possible to choose between the two in the settings page.
Again – just a suggestion. Thanks for a great plugin! :)
- 35January 10th, 2009 5:53 am
Asking @disqus if they will intergrate this seeing as i use disqus for my comments on my MT blog. I do not use WP.
- 36January 10th, 2009 7:30 am
hey,
thanks for the great plugin!
how can i automatically show the tinyurl of the article (which appears f.ex. in twitter) below my article? is this possible? - 37January 10th, 2009 7:36 am
Terrific concept, thanks for developing it.
I installed it on one of my blogs running WP 2.7, following the first two steps described above. But I get this error:
Parse error: syntax error, unexpected T_ENDIF in /[path]/www.nevillehobson.com/next/wp-content/plugins/thesis-openhook/thesis-openhook.php(279) : eval()'d code on line 7Any idea what I need to edit and where? Thanks.
[edit] Reading that code again, looks like it actually might be an issue with the theme (Thesis). I’ll post this on their support forum as well.
- 38January 10th, 2009 10:44 am
Wordpress 2.7 code version has error in 1-st line
1. if ( ! emptyempty($comments_by_type['tweetback']) ) :?>
must be
1. if ( !empty($comments_by_type['tweetback']) ) :?>
- 39January 10th, 2009 11:25 am
It would be great if this could be added as a Dashboard thing, but not set as visible on the site.
- 40January 10th, 2009 8:58 pm
Thank you super, this is a great post… You give me lot more idea now =)
- 41January 10th, 2009 9:51 pm
Awesomeness!
- 42January 11th, 2009 7:08 am
Hey all,
I really dig this plug-in, and I’m using it on my site ShortFormBlog, but I noticed a pretty significant problem cropping up when I was using it. For whatever reason, the app keeps calling up posts that aren’t actually there, and generating hundreds of tweetback comments for 404 errors.
Here’s a screenshot of what I’m talking about: Flickr
Any suggestions?
- 43January 11th, 2009 11:14 am
My comments.php file doesn’t contain the following line of code:
<?php endforeach; /* end for each comment */ ?>
Instead, it contains the following (with the proper brackets)
?php } /* end for each comment */ ?
I’m running WP 2.6, but the above code doesn’t appear in the 2.6 tutorial you linked to.
My comments form seems to work fine despite the weird code. Nevertheless, do I need to get someone to fix my comments.php code in order to make Tweetbacks work? (I tried to implement, but tweetbacks were not getting picked up, so I went back to the previous code for now).
- 44January 11th, 2009 2:41 pm
Great plugin!
I’m using Agregado theme on wp2.7, and while it counts the tweets, I can’t get them displayed.
Ideas?Also: comment date on tweets appear to be 1969. Hmph.
- 45January 11th, 2009 2:43 pm
I like this, great new wordpress marketing!
- 46January 11th, 2009 3:41 pm
There are some serious problems wiith this plugin.
1) tweetbacks are automatically approved
2) there is no way to show tweetbacks on the comments page (admin side), since the type has not been added to dropdown list, so you’d need to got through ALL your posts to check for twitter spam.Other than that it looks interesting but really, spam is an issue and always has been. Why would you not even think about it during implementation?
- 47January 11th, 2009 9:12 pm
There is a big problem with bit.ly integration for short URLs. I’m starting to receive in my admin comments panel ALL links created with this url shortener, so I’m getting filled with comments. The strange part is that these appear only in the admin panel (comments section) but are not published on the blog.
Well, it’s a problem anyway that you should fix ASAP - 48January 12th, 2009 12:33 am
I am having the same problem… my comments show 998 comments, only showing up in admin panel. Everything else seems to work, just dont know why I have a bunch showing in admin panel. I thought it was something in my code, but now I dont think so.
- 49January 12th, 2009 3:07 pm
thanks man ……..cool plugin
- 50January 13th, 2009 10:21 pm
cool new plugin! This integrates twitter interaction even more with our blogs!
- 51January 15th, 2009 8:39 pm
I was just talking with Dan Zarrella on Twitter about this several days ago. I am amazed to see this here already, good work! I had to Digg this & add it to Delicious too.
I will be implementing this on my Social Media blog: Tips on Enterprise 2.0 with Web 2.0 for Social Media I am a big fan of Twitter and just blogged about Twittertainment, looks like I need to let my readers know about this too.
Thank you,
- 52February 5th, 2009 11:44 am
Guess what? I got 142 pages of spam with this plugin See my post
- 53April 11th, 2009 10:10 pm
Does it work on wordpress 2.7.1 ?
- 54April 29th, 2009 3:36 am
This is awesome, but I can’t get it to work with my blog which uses Thesis Theme and Intense Debate.
Any help? :) - 55May 24th, 2009 7:29 pm
Bizcards Blog: I tried to do this with mine. It didn’t work. It would delete my Trackbacks and not display them. Plus, my Tweetbacks still show as comments. I retried it and it dropped the bottom comment area. So I guess I have to keep them as regular comments for the time being. Unless someone can help me with it.
- 56May 25th, 2009 7:30 am
i have use the latest version. do i need to add the code?
There is configuration in the version. can anyone advisSE:
- 00
There are no trackbacks at this time. If you are interested in leaving a trackback, please use this URL.
Leave a Comment
Make sure you enter the * required information where indicated. Please also rate the article as it will help us decide future content and posts. Comments are moderated – and rel="nofollow" is in use. Please no link dropping, no keywords or domains as names; do not spam, and do not advertise!
Interact
Popular
- 100 Wordpress Themes
- Photoshop Tutorials
- Fantastic Wallpapers
- 40+ Excellent Freefonts
- Dual-Screen Wallpapers
- Wordpress Themes for 2009
- Illustrator Tutorials
- Incredible Free Icon Sets
- High-Quality Free Fonts
- 30 Scripts For Galleries
- Photoshop Text Effects
- Useful Icon Sets
- Web Design Trends
- iPhone Wallpapers
- Before Launching a Website
- CSS Layouts And Templates
- Photoshop Actions
- Stunning Pictures and Photos
- Fantastic HDR Pictures
- Logo Design Tutorials
- Free Design Templates
- 10 Mistakes In Logo Design
- Photoshop Custom Shapes
- 40 Creative Design Layouts
- 8 Layout Solutions
- 53 CSS Techniques
- Photography Techniques
- Black & White Photography
- Styling Design Elements
- CSS-Based Forms
- 50 jQuery Techniques
- 50 Portfolio Websites
- 50 CSS Techniques
- Creative Logo Designs
- Desktop Wallpapers
- 25 Open Source Mac Apps
- 50 Free Icon Sets
- The Big Showcase Of Online T-Shirt Stores - http://bit.ly/5Tq8uA
- @ilmv oh ok then ;)
- @ilmv no, the SM Book will not be out of date :) We made sure it contains universal design, usability and marketing principles.
- Apple ad bombing Windows 7 on Google - http://bit.ly/28ctPq
- Atatonic - a fresh CSS framework - http://bit.ly/4oOV2w (via @umutm)
- @HrvojeKC yes, that's an interesting idea. Maybe when the waiting is over, we'll write a detailed post about it.



Thanks!
Now it’s tweetermania time!