Simple Twitter Widget – now as WordPress plugin
Some time ago I posted the code for a simple Twitter widget for WordPress. The code was pretty rough and far from perfect, but simple and reliable, so the post became one of the most popular ones on this website.
I was asked to release it as a plugin and so I spent a few hours, put everything in a nice widget class in WP 2.8+ style, added several improvements and bug fixes as well as a set of configuration options to make it more flexible.

Features
- No need to enter your Twitter password
- No Javascript
- Caching to save resources and for faster display
- Various options, like making links or Twitter usernames clickable
- Will display timestamp as ‘x hours/mins ago’ when status newer than 24 hours
- Supports multiple instances at the same time
- Fully compatible with widget-ready themes and WordPress 3.0
The plugin is hosted at wordpress.org with a screenshot and more information. You can also use the plugin manager built into WordPress for search and automatic install.
Big thanks to Justin Tadlock for his great tutorial on how to write widgets for WordPress.
Comments
are you going to release the code on your own twitter widgets? the ones to the left of this?
they look great!
That’s basically the code here, only with some CSS applied.
Great plugin – how can you style it with css?
Hi Adam, you can add some CSS styles to your WordPress theme stylesheet. The container surrounding the widget has class ‘twitter-widget’. Inside there is an unordered list (ul) and each tweet as a list item (li). The date has class ‘twitter-date’, the text has class ‘twitter-text’.
awesome! thanks Matt!
No worries. Enjoy :)
Just downloaded this plugin from WordPress on to my blog. I found that when I added my username, the widget is pulling my feeds from HootSuite. So whichever Twitter account I am in on HootSuite, those are the twitter posts that show up.
How can I designate one Twitter account only?
Thanks!
@NJMeans: sorry without knowing how Hootsuite integrates with WordPress, what your setup and configuration is, which other plugins you have installed in WordPress etc., there’s not much I can say. The plugin is very simple and connects directly to Twitter, there’s not much that can go wrong. Maybe you have other plugins installed that cause interference.
Just what I was looking for. Placed it on my site. Thank you!
Thanks :), looks good!
Hi, is there an easy way for me to use this without widgets?
Not sure why you would want to do that but if you know PHP then you could easily copy the main function from the source code and strip out the stuff that you don’t need. Code is well documented.
Hey Matt,
If your twitter widget displays like it does on your site it is by far the most aesthetically pleasing and flexible one around. Great Job!
I just wish I could get it to function on my site. http://www.adamwalker.biz The plug-in loads properly and displays the title properly once I move the widget into the side bar. I just cant get it to recognize my twitter account. Any thoughts? I changed the interval refresh rate as suggested with no luck. It doesn’t give me any error messages either unless i type in something bogus. It just doesn’t load any tweets in the box. So kind of at a loss.
If you have any ideas I would appreciate your input. If not I understand.
Dig your site too btw. Have a great day!
Hi Adam, it looks like your homepage stops loading just when the Twitter widget is loaded. I presume there is a PHP fatal error somewhere that stops WordPress. You should check your PHP log files to see which file causes the error. If you don’t have log files, try making your site display the error using PHPs ‘ini_set’ function.
If it turns out the error is caused by the Twitter widget please send me the logs so I can check what’s wrong.
Hi Matt
For some reason, the widget has suddenly stopped displaying any tweets. I upgraded to the latest version, deactivate, reactivated etc etc, but still no joy.
Any thoughts?!
Many thanks
Adam
Hi Adam, it looks like it’s the same issue that the previous commenter had, the page stops loading at the widget, probably because of a PHP fatal error. Can you please check your PHP error logs and send me a copy of the entry, if the error is caused by the widget? I haven’t had this problem before and to investigate I need to see what’s causing WordPress to halt.
Hi Matt, thanks for getting back. I think it must be the twitter widget, because when it’s enabled, it stops my footer loading (which is the next thing in the code after this widget). If I disable the widget, then my footer displays fine. I’ll try and get the error logs.
thanks adam.
I’m having this same problem as described by Adam after upgrade to 3.0.1.
Hi Scott, in my own tests with 3.0.1 I didn’t see anything wrong. Unfortunately the previous authors didn’t get back to me with error logs. If you have any PHP error logs or if you see error messages, please send it to me, then I can investigate the issue.
Installed and set up easily with WP3.0.1 thanks.
Is there any way of wrapping text that is wider than the widget? A twitter list has more characters than the usual words posted, so therefore it creeps into the main column of text (widget is in my left sidebar).
Hi Tim, yes there is. Simply add
word-wrap: break-word;to the list item CSS, in your case add it todiv.widget ul li. This allows browsers to break unbreakable words. See here. Alternatively you could use a URL shortener.