Display your tweets without a plugin

18 January 2009 in Tutorials

tagged with , , ,

I’ve seen people use some rather hefty plugins on their blogs to display their recent Twitter action and a couple of people have asked me how I display my tweets. Well, I’ll tell ya! The essential bits are only about 3 lines of code.

A touch of javascript

There’s two bits of javascript that you can place anywhere on the page. A good spot is at the very end of your markup, before </body>: if Twitter has a hiccup, the rest of your page will load first.

<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/username.json?callback=twitterCallback2&count=1"></script>

Watch out for that bit in the second line where it says “username”. You should replace that with your own twitter username. You can also change count=1 if you want to show more than one tweet.

If you’re using the Thesis theme. You can insert that toward the end of your page using the following code in custom_functions.php.

function footer_scripts() { ?>
	<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
	<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/username.json?callback=twitterCallback2&count=1"></script>
<?php }
add_action('thesis_hook_after_html', 'footer_scripts');

A dash of HTML

Then in the spot on your page where you want to show your latest tweets, you place the following code.

<div id="twitter_div"><ul id="twitter_update_list"><li>&nbsp;</li></ul></div>

The way this little bit works is that the javascript, when it loads, replaces anything inside <ul id="twitter_update_list"><li>&nbsp;</li></ul> with the tweets. An example of what it ends up looking like from my Twitter stream is:

<ul id="twitter_update_list">
	<li>
		<span>@<a href="http://www.twitter.com/matpacker">matpacker</a> OMG, hope you're not too damaged!</span> <a href="http://twitter.com/kristarella/statuses/1122887200" style="font-size: 85%;">19 minutes ago</a>
	</li>
</ul>

For any widget enabled theme, the HTML can go in a text widget to appear in one of the widgetized areas of your blog (usually sidebar, but some themes offer more widget areas). Or you can insert it into one of your theme files.

For those on Thesis who want to insert it with a hook with custom_functions.php… For example, into your sidebar,

function twitter_widget() { ?>
	<li class="widget">
		<div id="twitter_div"><ul id="twitter_update_list"><li> </li></ul></div>
		<p><span class="bracket">{</span> <a href="http://twitter.com/username">Follow me on Twitter</a> <span class="bracket">}</span></p>
	</li>
<?php }
add_action('thesis_hook_after_sidebar_1', 'twitter_widget');

Or, you could put it in your footer as I have. Take a look at my Thesis footers tutorial for details on setting up a fat footer.

Mix in some CSS

You don't need a plugin to show your tweets

You don't need a plugin to show your tweets

Then all you need is a bit of style. I added an image by darkmotion and available at Function. Find some you like in this Twitter icon roundup. I just popped the image in with HTML, like so,

<div id="twitter_div"><ul id="twitter_update_list"><li>&nbsp;</li></ul><img src="<?php bloginfo('template_url'); ?>/custom/images/twitter.png" alt="" /></div>

Since I wrapped my Twitter code in a widget it already had proper widget text styles and I only needed a little bit of CSS.

.custom #twitter_div {padding:0.625em; border:3px double #ddd; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px;}
	.custom #twitter_div img {float:right;}

I implemented this code when I first jumped on Twitter, but for some reason, this simple bit of code seems harder and harder to find on their site. So now, here it is for you all to enjoy.

Don’t forget to follow me on Twitter!

{ 9 trackbacks }

Kudos to All The WordPress Plugin Developers - This is for You : Kasper Sørensen
31 January 2009 at 05:09
Twitter Widget
15 March 2009 at 05:47
links for 2009-04-01 | girliegeek
1 April 2009 at 18:03
This Week in Thesis — January 18, 2009
6 May 2009 at 17:31
Swoosh Away! - A free wordpress theme | Angad Sodhi
17 June 2009 at 08:53
Daily Digest for September 5th
6 September 2009 at 14:17
Daily Digest for September 6th
7 September 2009 at 10:19
20 Best Twitter-likes And Useful Tutorials To Work With Twitter | AEXT.NET
22 January 2010 at 19:56
Custom Twitter Widget For the Thesis Wordpress Theme
10 February 2010 at 08:46

{ 110 comments… read them below or add one }

1 Shae 18 January 2009 at 12:51

Great tutorial! Thank you so much!

2 JHS 18 January 2009 at 12:53

Obviously, I did something wrong. I tried to follow it, but I am using the Open Hook plugin. Could you give step by step instructions for those of us using it?

Thanks.

3 kristarella 18 January 2009 at 13:23

Cheers Shae!

JHS, using OpenHook you would treat the code as if you weren’t using Thesis.
Add into the After HTML box:

<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/username.json?callback=twitterCallback2&count=1"></script>

Don’t forget to put your own Twitter username.

And if you want the widget to be in the sidebar either add
<div id="twitter_div"><ul id="twitter_update_list"><li>&nbsp;</li></ul></div>
into a text widget. Or add,

	<li class="widget">
		<div id="twitter_div"><ul id="twitter_update_list"><li> </li></ul></div>
		<p><span class="bracket">{</span> <a href="http://twitter.com/username">Follow me on Twitter</a> <span class="bracket">}</span></p>
	</li>

into one of the sidebar boxes (e.g. Before Sidebar 1) of OpenHook.

You seem to have it working now though. ;)

4 JHS 18 January 2009 at 13:33

OK . . . I figured it out. I am slowly but surely getting the drift on the Open Hook plugin. i’m a slow learner. :-)

Thanks for yet another fabulous hack!

5 Bruce 18 January 2009 at 13:39

@kristarella — Great coding. I’ll look into doing this. I may want to supplement it slightly by figuring someway to keep @replies from showing … some of mine are rather, well, indelicate, and would be best not shown on my blog. I suppose I could do some php to check for the use of an @ and just not show any tweets that contain them (thinking out loud). Anyway, great job and thanks for sharing it!

6 Ben Barden - Blog Tips 18 January 2009 at 13:46

It doesn’t look as good as yours, but you can add a simple “latest tweets” box by adding an RSS widget. I’ve added it to my blog if you want to have a look.

7 kristarella 18 January 2009 at 13:49

Thanks Bruce!

Yeah, could be hard to exclude replies, because then you might exclude good re-tweets as well? There might be something in the Twitter API that tells you how to do that. Not sure.

8 Ben Barden - Blog Tips 18 January 2009 at 13:58

It shouldn’t be too difficult to exclude replies, if you want to, of course. The following PHP should work:

if (substr($strTweet, 0, 1) == “@”) {
// don’t display
} else {
// display
}

Just wrap that around the code that displays each tweet, store the value of each tweet in the $strTweet variable, and add PHP tags as needed.

9 kristarella 18 January 2009 at 14:07

Thanks Ben! Two very good tips. Lovely!

10 Bruce 18 January 2009 at 14:12

@kristarella, Good point, but looks like Ben has a great workaround that doesn’t exclude retweets.
@Ben Much thanks … I like how cleanly you handled that.

And again, kristarella, thanks for sharing!

11 Claude 18 January 2009 at 14:23

@bruce: Your own timeline won’t have any replies from others. But you can always use the Yahoo! Query Language (YQL) to select a subset of your statuses.

For example a YQL query like the one below will return my last 5 statuses that contain a link:

select status.text from xml where url = 'http://twitter.com/statuses/user_timeline/betancourtcode.xml?count=5' and status.text like '%http://%'

Make sure to select JSON output and provide a callback function, like twitterCallback2.

12 kristarella 18 January 2009 at 14:31

Claude, thanks for the input. That’s really useful to really hone the usefulness of the tweets we show on our sites. Cheers!

13 Bruce 18 January 2009 at 14:46

@claude, Fascinating stuff. Thank you for sharing. BTW, your site looks impressive … a lot of great programming information. Thanks again.

14 Vinod Yadav 18 January 2009 at 20:48

Hi,
I can’t seem to be adding it into the blog, I’ve added these two lines of code

 

vinod407 is my username.
Thanks in anticipation.

15 kristarella 18 January 2009 at 23:45

Sorry Vinod, your code didn’t come out in the comment.

You need to encode HTML in comments, so that when you’re typing a < looks like &lt; and a > looks like &gt;.

However, if you’ve only added two lines of code then it’s probably not enough, you have to add the two lines of javascript at the start of the post and then the bit of HTML later for it to work.

16 Mobiles NZ 19 January 2009 at 04:18

Yes, also should add it via notepad or something like Dreamweaver will mess up the code.

17 BrianP 19 January 2009 at 04:42

kristarella this is Rad. Thank you so much.

I am having a little trouble on getting the style. I am using Open hook as well and I am not sure where to paste the HTTP code in that displays the twitter icon. I have uploaded an image to my customs.image folder, but still not having luck. I am new to thesis and trying to set up my new blog as we speak. Thanks again.

18 kristarella 19 January 2009 at 08:01

Brian, the code with the image corresponds the the HTML that you put in a text widget, or sidebar OpenHook box. You need to replace part of that first HTML with the latter one containing the image.

19 Lee 19 January 2009 at 09:24

I’ve always liked your latest Twitter post thingy and I think you’ve talked me through it before but it’s nice to have it here as a reference.

I’m currently just using the standard thing that you can generate with at Twitter but I’m considering doing what you’ve done here.

Cheers

20 kristarella 19 January 2009 at 09:35

Hey Lee,

Wow, I didn’t realise/had forgotten that Twitter offered any widgets. It’s so well hidden at the bottom of the page under “Apps”. I clicked through there, and through to the Widgets page and then to the HTML widgets page and realised, that’s where I got the code from in the first place!

I posted it here because several people asked me how to do it and I could not find the instructions on the Twitter page. Oh well, their poor navigation has been my gain in new followers.

21 Mark Forman 19 January 2009 at 12:12

Nice job and thanks for sharing. Worked like a charm on first go.

22 Caity 19 January 2009 at 14:44

Oh my gosh! Thank you so much for this!

23 Tyler @ Building Camelot 20 January 2009 at 02:38

Very cool – too bad I have some damn meetings today or I’d play around with this right away. Thank you!

24 Robert 20 January 2009 at 10:12

Krista,

I got your code working except for the div tag for the twitter image. Where would I be placing that code? Thanks so much!

25 Dave C 21 January 2009 at 02:04

Great little bit of code! Thanks for sharing.

Dave

26 Pasquale 21 January 2009 at 02:46

Great to see my little chirpy fella tweeting :D

27 Birdfreak 23 January 2009 at 01:49

That is the best tutorial for adding Twitter to a blog. Superb job A+++

28 lawton chiles 25 January 2009 at 10:30

I put it in the sidebar but I think I messed something up using open hook. I need to add a Twitter icon now right?

29 kristarella 25 January 2009 at 11:02

Robert — the line that includes the Twitter image replaces the line in the previous code block that starts with the same div id="twitter_div".

Pasquale — thanks for the little fella. Love your work, and love getting some of them for free too ;)

Lawton — you didn’t mess anything up, but it would probably help the styling if you wrapped the whole thing in <li class="widget"> code, as per my previous comment about using OpenHook. Then it will inherit the correct font sizes. Using an image is totally up to you. You don’t have to. :)

30 lawton chiles 25 January 2009 at 11:11

I think i did it. can someone check? It’s on my sidebar

31 lawton chiles 25 January 2009 at 11:13

I go and add it where, the widget tag? in the custom css code or one of the Open Hook boxes?

Thanks!

32 lawton chiles 25 January 2009 at 11:16

I added this before the Custom CSS code:

<li class=”widget”

and then closed it after the Twitter code with but I think it broke the border around it.

33 kristarella 25 January 2009 at 11:26

Lawton — that looks good now, whatever you’re doing is good. Previously the text was really small and the list items had bullets, but now it looks like right. Don’t know about the border, but I don’t know that you really need one with that positioning. :)

34 rumblepup 26 January 2009 at 18:55

I’ve got a simple solution as well. Drag an standard rss widget onto your preferred sidebar, position it where you want it, and do a search on search.twitter.com for your username.

So we search for kristarella and then grab the rss feed and load it into our rss reader. Neat huh?

35 kristarella 26 January 2009 at 19:10

rumblepup — Yep. It is pretty neat… and already mentioned by Ben. Actually, you don’t even need to use the search query; there’s a link to the RSS of your timeline at the bottom of your profile page.

I think I prefer the format of the API method: it has the timestamp and is a bit more flexible with styling. :)

36 lawton chiles 27 January 2009 at 03:58

kristarella, thanks so much! you rock

Care to do an interview about your work on chilesadvertising.com?

37 Charity 28 January 2009 at 16:18

Sweet. I was just about ready to (unenthusiastically) bring in Alex King’s Twitter plugin (which I’ve been using forever) to a new design I’m working on when I saw this article! Nothing against his plugin, but it does seem sluggish. Additionally, there’s a bug of some sort that adds a redundant custom field to any post/page, many times over. I had to delete 22 of them earlier this afternoon! I have no idea what could be causing the problem but I suspect it may be tied to WP’s autosave feature. Anyway, I’m anxious to try your method and spare myself the headache – not to mention load time! :)

38 kristarella 28 January 2009 at 18:41

Charity — I know! I got so annoyed with those duplicate custom fields that I got rid of that plugin and started using TwitterFeed. It’s been really cool, I have my Delicious bookmarks going there and my new blog posts. People always say thanks for the bookmark links and comment on my new posts.

Make sure you put the javascript in your footer. If it gets hung up, the rest of your page will load first and your Twitter box will just be empty until it loads and inserts the content.

39 Shae 1 February 2009 at 02:00

Ok, I need a little help please. The widget displays just fine in the sidebars, but if I hook it after the multimedia box, I’m getting a bullet on the outside. I’ve tried to figure it out on my own, but I’m stumped. Can anyone help me out?

40 kristarella 1 February 2009 at 08:18

Shae, looks like you got it fixed?

41 Shae 1 February 2009 at 08:21

Yep, I just figured it out. Wonders what a nap will do for the brain. Thanks for checking!

42 Jonathan 12 March 2009 at 09:12

Kristarella or Shae, pleeeese tell me how you got rid of that bullet!!! driving me crazy! And thanks Kris for the great tutorials!

43 kristarella 12 March 2009 at 12:50

Jonathan, you probably need .custom ul#twitter_update_list {list-style:none;}.

44 Jonathan 12 March 2009 at 21:05

Perfect! Thank you so much Kristarella!

45 Blake 31 March 2009 at 17:19

Thank you, Kristarella, for this enormously helpful tutorial. My question: would it be possible to combine two different twitter accounts into one single feed? For a 2-author blog. The only options I’ve been able to find are using services like Yahoo Pipes to create an RSS feed, which is a bit clumsy, harder to style, and doesn’t have the timestamp. I know zero javascript, so I don’t know how difficult this would be. Any ideas?

46 kristarella 31 March 2009 at 18:19

Blake, I don’t know any way you could do it with the javascript method (I don’t know that much JS myself). The only way I would think to do it is to use the Twitter RSS feeds (link is at the bottom of your Twitter profile page) and use Feedburner or another service to combine them.

47 Greg 1 May 2009 at 23:22

Hi. I’m looking for a way to display (on my HTML page) just the text of a tweet with no bullet and no indicator at the end saying how many minutes or hours ago it was posted. Do you think there’s a way to modify your code to do this? Many thanks for any help.

48 kristarella 3 May 2009 at 16:51

Greg — with this method the only way to hide that stuff is with CSS:

ul#twitter_update_list {list-style:none;}
ul#twitter_update_list li a {display:none;}
ul#twitter_update_list li span a {display:inline;}
49 Greg 4 May 2009 at 01:59

Thanks, Kristarella. That worked for me. Is there also a way to drop the link so that all I get is the text?

50 kristarella 4 May 2009 at 13:05

Greg — which link is that? If it’s the ‘follow me on twitter’ link, just delete that whole paragraph from the code, it’s not part of the essential bits to make the javascript work. If it’s a link to someone’s username because it’s a reply tweet, then there are a couple of suggestions in previous comments for not displaying replies.

51 IsaiahC 7 May 2009 at 04:02

Thanks for the tutorial, Kristarella. Followed it and I love how it looks!

Problem now is that I’m trying to place it right next to the title but making no headway. I should add that I’m hopeless at CSS. Tried a few tips and tricks on the Thesis forum as well but they all didn’t do anything for me.

I was wondering what the best way to achieve that might be, besides dropping the idea of course?

52 kristarella 7 May 2009 at 12:37

Isaiah — you need to give #logo and #tagline a width so that they fit next to the twitter dive, because by default they spread the whole width of the header. Then insert twitter before the title and float it to the right.

53 IsaiahC 7 May 2009 at 12:39

Kristarella:

Ah, now it makes sense! Thank you for the tip, Kristarella!

54 Dr. Patrick MacNamara 13 May 2009 at 09:22

Kristarella,

Thanks for the wonderful tutorial. I incorporated it into my newly launched blog and it works like a charm.

One question: How can I set the position/order in which it displays in the sidebar?

For example, each time I enable a new widget, the Tweet section gets pushed further down the page. I’d like it to stay in position 4 right underneath the “Email Updates” widget.

Is this possible?

Thanks in advance!

55 kristarella 13 May 2009 at 10:37

Patrick — you would need to put the code into a text widget and then drag and drop the widget to above the others.

56 Daphna 17 May 2009 at 02:02

Hi
Thx for the fix, worked like a charm!
at first.
at some point i noticed this wierdness, so i tried switching it to the code from the twtr site but sill the same, maybe u know why –
On my Mac everything works cool
On my Win laptop the tweet is always displayed as “less then a minute ago” even when its been hours since i last twat. (again, safari and ff show this just as it should be).
I dont mind deleting the part that counts the time, i just dont know which part of the code is it.
any chance u can help ?
thx

57 kristarella 17 May 2009 at 12:01

Daphna — I don’t know how to delete it with this method, only hide it with CSS as per my previous comment. Cheers.

58 Daphna 18 May 2009 at 03:48

hi, my bad, i blamed windows – the usual suspect – but it was all my fault – i changed the date in my lap top to a few months back for some particular reason and forgot all about it. and thats why it couldnt “digest” the time info from twitter as it should have. all good now. THX – and sorry for the bother:)

59 Jami 21 May 2009 at 13:55

Hi Kristarella, I just wanted to say thank you for all your wonderful tutorials. Your nav menu one helped TONS when I was adding a second menu to my thesis theme. I’m working all the bugs out offline, but I had to say thanks. This twitter coding works like a charm. Stumbled!!

60 Peter Kindness 24 May 2009 at 12:56

Hi Kris,
I tried to follow this tutorial and get stuck about where to add the CSS (Custom CSS – I now guess)…anyway, I gave up on the mod and decided to settle with the Twitter Widget and I’ve uninstalled everything from your tutorial but the Twitter posts are still coming through!? There’s no HTML Text Widget active, I’ve cleared the custom_functions.php and even reinstalled Thesis 1.5. But it’s still there!? Very odd – can you help me please?
Thanks,
Pete

61 kristarella 24 May 2009 at 14:45

Peter — the only Twitter stuff I can see on your site is a Twitter widget inside a text widget. It doesn’t have anything to do with the code in this tutorial. If you don’t want that one, remove the text widget.

62 Kerrie 6 June 2009 at 00:32

Hi Kristarella! Thank you very much for this! Your code makes my twitter display look amazing. I’ve learned a ton from some of your other tutorials too. Thanks again!

63 Johnny 30 June 2009 at 21:42

I use it on my own site which is working well but have a few problems, not sure if you can help but…

A – I’m looking for a way to exclude @reply messages I send to other users
B – The formatting when displaying @replies gets screwed up

If you can help that would be fabulous!

Thanks

64 kristarella 1 July 2009 at 00:05

Johnny — I haven’t tried to exclude the replies, but you could try to do that with the PHP in a previous comment.

The reason the formatting is messed up is because of the CSS:

#twitter_div ul li a {
	width:65px;
	display:block;
	position:relative;
	top:-43px;
	left:-90px;
	line-height:19px;
	text-transform:capitalize;
}

You’ll need to override that positioning for links that are inside the tweet content, which are inside a span. E.g., #twitter_div ul li span a {top:0; left:0; display:inline;}.

65 Darren 13 July 2009 at 02:19

Exceptionally helpful thank you!

66 Martin 17 July 2009 at 08:29

Thanks for the great tutorial!

Sadly the twitter feed comes up blank on networks where twitter is blocked (as in more and more corporate networks). Is there a work-around? I was hoping for an alternative to the plug-in “Twitter for Wordpress” which more often than not fails with the mention “No public Twitter messages”.

Anyway, thanks again.

67 kristarella 17 July 2009 at 09:24

Martin — I don’t really know what method they use to block things so I’m not sure how you would combat it. You could try putting your Twitter RSS feed (link in the sidebar of your profile page) into an RSS widget.

68 Jacob Yap 8 August 2009 at 17:07

Thank you for this great tutorial, especially for new Thesis user like me. Great work. ;)

69 Cobus Taljaard 9 August 2009 at 22:26

Hi – great discussion this!
I was wondering about the twitter timeline of posts. Would it be possible to display a random tweet from a singel user’s feed?

70 kristarella 10 August 2009 at 13:21

Cobus — Sorry, I can’t think of any way to do that with this javascript method. You might be able to save the javascript file and edit it to get a random tweet, but I’m not sure. I think a better approach would be to parse the RSS feed of your tweets and store them up then choose one randomly with PHP.

There’s a tutorial on parsing feeds… I think Magpie comes with WordPress already if you’re using WordPress. Obviously there are more steps than it that tutorial to get to your goal. If you’re interested in pursuing it and need some assistance let us know. :-)

71 Mokie 20 August 2009 at 18:59

Hello.

I have previously used a php code to show my twitter updates on my blog. Problem with that is that it doesn’t seem to update the twitter updates before it has gone many hours, and sometimes never.

Wanted to try out you simple code. Placed the code inside my tweet.php which I upload inside my header.php. It doesn’t work. I have also tried to placed it inside in my tweet.php.

Any idea why it doesn’t work?

72 Mokie 20 August 2009 at 19:01

ment to have been: “I have also tried to placed it inside my body /body tag in tweet.php.”

73 Brandon 4 September 2009 at 05:03

How do I pull the profile_image_url?

74 Brandon 4 September 2009 at 07:58

Nevermind…

If anyone is interested:

$username = twitter;
$xml = simplexml_load_file("http://twitter.com/users/".$username.".xml");
$image = $xml->profile_image_url;
echo "<img src=’".$image."’>";

75 kristarella 6 September 2009 at 01:16

Mokie — Sorry, I was sure I replied to you, but did so via my mobile… maybe it went to the spam and I missed it by a couple of days on the auto delete.
I think the essence of my comment was that I don’t have enough information to help you, the key to this technique is calling the javascript files somewhere on the page and making sure that the correct HTML is within the body of the page. That’s it. If you only inserted the code into the head of the document, that won’t work. Without understanding the nature of your tweet.php file, I can’t tell you much more at this point.

Brandon — thanks for sharing that!

76 Alyssa 14 September 2009 at 10:14

Thank you so much for this tutorial. I also want to exclude @ replies, but the comment about PHP isn’t quite thorough enough for me to understand. Do you think you could elaborate?

77 kristarella 14 September 2009 at 11:33

Alyssa — having looked at it a bit more, I’m not sure how you could exclude Tweets gathered with this method via PHP. The reason being that this method uses javascript to add the tweets to the site after it’s loaded. However, PHP processing happens before the page is loaded…

You could try downloading the Twitter blogger.js file and edit it to exclude replies. I’m not 100% sure how it would work (I’m not that strong in javascript), but it might involve changing the line document.getElementById('twitter_update_list').innerHTML = statusHTML.join(''); to

if (reply) {}
else { document.getElementById('twitter_update_list').innerHTML = statusHTML.join(''); }

However, that would probably result in a blank tweet whenever the most recent was a reply. If you know anyone good with javascript I would ask them how to do what I’m trying to do above, but more effectively ;-)

78 Andrew 15 September 2009 at 20:32

This is all very well but it assumes that javascript is turned on also twitter is constantly plagued with server issues.
Andrew

79 kristarella 15 September 2009 at 22:49

Andrew — I consider the display of tweets to be a superfluous nicety and not primary content. So, if someone has javascript turned off and doesn’t see the tweet, I’m not really fussed. If someone has javascript turned off they are going to be missing a significant part of the web experience, including much of the functionality of Twitter’s own pages.

If your comment about the server issues is in regard to using their hosted javascript file, there is nothing preventing you from downloading and hosting that file yourself. If it’s in regard to being able to fetch those tweets at all while their server is overloaded, then many more techniques other than javascript will also be affected by outages.

If you’re after something completely reliable and completely customisable you will probably need to host it yourself. For that you will need either knowledge greater than my own to fetch your tweets and store them yourself, or a plugin or external bit of software, which in the end defeats the whole premise of this post. I don’t think there’s anything wrong with using a plugin, I just chose not to and chose to use this method and share it.

80 Andrew 16 September 2009 at 00:30

I absolutely agree with you and feel that most people will go down the route of using a plug in which considering the time and effort put in by the contributor /developer is too good to be true :)

When I returned from holiday a website I link to was displaying errors because twitter was down so again, you are right if reliability is a concern for displaying content the primary source needs to be on your own servers. I think it’s only a matter of time that twitter will need additional investment for the server resources or be forced into selling to google, which is inevitably really.

81 Nicholas 16 September 2009 at 00:56

Great tutorial!

I went the Openhook route.

Even re-sized the bird and made him a little darker.

Everything is installed Before Sidebar 2

However, no tweets show up in my box =\

Your thoughts on why this might be happening?

82 kristarella 16 September 2009 at 08:55

Nicholas — looks like you haven’t put the javascript anywhere on your page: have a look at the first part of the post.

Andrew — you’re right. They will need to continue to invest more in server resources. I hope that they can find the money and support to do that without selling to Google… the rumours of selling a little while ago were erroneous: they were just in talks to index Twitter content, which they weren’t doing before. Perhaps development into the API will strengthen Twitter as well so that errors don’t occur when they’re down. I’ve seen an API popup asking for a password on some sites when Twitter was spazzing.

83 Andrew 17 September 2009 at 16:54

Hi Kristarella, I have just back tracked to see how I came to your ‘twitter feed solution’ and having re-read the thread and looked at the home page I can’t see a plugin link :) Is there one or is it all within the tutorial?
I plugged WP addon in a few weeks ago and it broke some of the layout which I notice has happened for this one too, in the side bar.
Andrew

84 kristarella 17 September 2009 at 17:12

Andrew — No. There are no links to any plugins. It’s all in the tutorial; thus the title “Display your tweets without a plugin”

85 Andrew 17 September 2009 at 17:42

I can’t believe I’ve read the tutorial and missed the title, sorry. I guess this would work for any site and not just a WP site?
Andrew

86 kristarella 17 September 2009 at 19:47

Andrew — Hehe, no worries… just confused me a touch ;-) Yes, it would work for any HTML page :-)

87 Nicholas 29 September 2009 at 07:35

Great! Got it working and the feed updates just fine thank you!

Was wondering how to give it a sidebar title like “Twittering,” for example, so it doesn’t look like just a bunch of tweets? I tried adding Twittering in with the sidebar hook “before_sidebar1″ but that seemed to place the “Twittering” just above the widget but not essentially in the widget.

Thx in advance! =)

88 kristarella 29 September 2009 at 09:24

Nicholas — Just after <li class="widget"> put <h3>Twittering</h3>.

89 Designer 16 October 2009 at 03:25

Is it possible to see 2 users in 1 single box? :)

90 kristarella 16 October 2009 at 07:51

Designer — Not with this method. If you want to do something like that you could burn the two Twitter RSS feeds into one with Feedburner and use a WordPress RSS widget or the Feedburner HTML widget (I think it’s under “Publicize”) to show it.

91 George Serradinho 11 November 2009 at 01:54

Thanks for this info, I tried and it worked for me. Now all I want is to style it a bit better :)

I prefer to use a function and code details and not install plugins, try and keep plugins to a minimal if possible.

92 Reuben Saltzman 12 December 2009 at 08:58

Thanks for the great info! It worked perfectly for me on my first try, and I have no idea what I’m doing.

93 JamesSpratt.org 14 December 2009 at 09:46

Nice one, thanks for this, have been using Alex King’s Twitter Tools but I just find it too bulky and his mugshot irritating!

Thanks for putting this out there,

James

94 Alex 16 December 2009 at 14:18

Hi,

Awesome! Now i have one stupid question:

Would i be able to display two twitter user feeds in seperate widgets with this? I got mine working and if we can get @kilted_andrews too we could eliminate 1 more plugin from our site.

95 kristarella 17 December 2009 at 10:48

Alex — You would have to download the blogger.js file from Twitter and change the element name that’s used by the script from twitter_update_list to twitter_update_list_2 in both the JS file and your HTML, you would then need to reference both the original and new blogger.js files, one for each username displayed.

96 Nathan Loding 4 January 2010 at 05:03

Kristarella — nice post, this worked out quite well. I was getting sick of the bloated plugins and obtrusive markup. This works wonderfully and it’s so simple!

97 Mark Batup 7 January 2010 at 02:45

I’m using this code quite successfully, however one thing I wanted was a break between the tweets as I’m display 4 tweets.

Any help you could give would be great.

Thnx and just followed you on twitter

98 kristarella 8 January 2010 at 23:40

Mark — CSS to the effect of #twitter_update_list li {margin-bottom:1em;} should do the trick.

99 Jé Maverick 15 January 2010 at 22:35

Thanks so much for this Kristarella. :)

100 Robert Uridge 19 January 2010 at 04:27

Happy Birthday “Display your tweets without a plugin”!

When I try to implement this it always misses out my latest tweet. So if I set count=10 It only shows 9, missing out the latest. If I set count=1 I get nothing.
Has anyone else run in to this problem? / Have any ideas as to what’s going on here.

101 kristarella 19 January 2010 at 10:14

Robert — Wow! You’re right. Can’t believe this post is a year old! Still as relevant as the day I wrote it too, that’s nice ;-)

Sorry, but I’ve never seen that issue before. That’s very odd. Have you tried it after adding more tweets on Twitter? Maybe there was something wrong with a particular tweet that wasn’t coming through the API properly or something.

102 ReneeW 23 January 2010 at 02:01

I’m working on a new blog and I’m trying to get the twitter image up. I am using hooks and took the html directly from twitter into my ‘feature box’ hook. Here is my html:

<div id="twitter_div"><h2 class="sidebar-title">Twitter </h2><ul id="twitter_update_list"></ul><a href="http://twitter.com/reneewphoto" id="twitter-link" style="display:block;text-align:right;">follow me on Twitter</a></div><script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script><script type="text/javascript" src="http://twitter.com/statuses/user_timeline/reneewphoto.json?callback=twitterCallback2&amp;count=1"></script>

How do I insert an image in this? I’ve read a lot of the other comments and tried to do it on my own with little success, any help would be awesome. Thanks

103 kristarella 25 January 2010 at 09:10

Renee — Perhaps if I reformat the HTML it will be a bit easier to see what’s happening:

<div id="twitter_div">
	<h2 class="sidebar-title">Twitter </h2>
	<ul id="twitter_update_list"></ul>
	<a href="http://twitter.com/reneewphoto" id="twitter-link" style="display:block;text-align:right;">follow me on Twitter</a>
</div>
<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/reneewphoto.json?callback=twitterCallback2&count=1"></script>

You can add the image anywhere, except within <ul id="twitter_update_list"></ul>.

Here is a version with the image inside the link and after “follow me on twitter”.

<div id="twitter_div">
	<h2 class="sidebar-title">Twitter </h2>
	<ul id="twitter_update_list"></ul>
	<a href="http://twitter.com/reneewphoto" id="twitter-link" style="display:block;text-align:right;">follow me on Twitter <img src="twitter.png" alt="" /></a>
</div>
<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/reneewphoto.json?callback=twitterCallback2&count=1"></script>
104 Robert Uridge 26 January 2010 at 00:44

Having looked further in to my previous problem it seems to be RT that are not showing up. Has anyone else experienced this? If so any solutions?

105 kristarella 27 January 2010 at 10:45

Robert — Sorry, not sure what the issue there is. Perhaps Twitter changed something in the API, or I’ve just never noticed it before.

106 Matth Jenks 12 February 2010 at 02:28

Wow, this was freakishly easy. I had this working within minutes of finding your page.

Thanks for sharing, and making it easy.

107 Damon 25 February 2010 at 02:36

Hi, first off great tutorial! Thank you for your time and energy!

Do you have a suggestion to space my two tweets on the home page? It actually did it once I implemented the code you have here. I woke up this morning to check the page and the two tweets are jammed together! You can see the “box background” I created for them to sit is larger on the bottom side, it looked great, now it’s a traffic jam!

http://www.theartfulbean.com

Any suggestions would be greatly appreciated!

Stay well.

108 Damon 25 February 2010 at 07:12

Opps, sorry. Just found the solution up above.

Seems I’m the type who looks at the pictures. :D

Thanks! Stay well.

109 Christian 2 March 2010 at 05:55

I´m currently working on a Twitter-Module for a very outdated joomla!-distribution and your “hard-coding”-tutorial was most helpful.
Thank you very much for your crystal-clear explanations!

110 Thesis Theme Design 11 March 2010 at 21:10

Another good post Krist!!!

I think applying these code on Thesis rather than having a plugin will not reduce the Website speeds too….

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Want to show PHP or XHTML code in your comment? Encode it first so that WordPress doesn't strip it away.

Read the comment policy.

Previous post:

Next post: