While working on the redesign of my website I realized I was using a very inefficient method of displaying my latest Twitter post (“Tweet”). Currently I’m using a script I found online that uses two functions that are just over 20 lines of code total. Here I’ll show you how to use WordPress’ built in RSS parser to display your latest tweet in 5 lines of code (thus this will only work on WordPress).
Note: An important aside about this script is that by default WordPress caches the feed for 1 hour. This means your Tweet on your website will be updated at that frequency. This is great because it saves your server a lot of overhead, especially on busy website. However, if you’re an avid Twitterer and want your very latest Tweet shown for every page refresh for every visitor, I recommend using this method.
function wp_echoTwitter($username){
include_once(ABSPATH.WPINC.'/rss.php');
$tweet = fetch_rss("http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1");
echo $tweet->items[0]['atom_content'];
}
Past the above in your functions.php file. Now just paste the following in your theme file where you want your Twitter post to appear:
<?php wp_echoTwitter('johnkolbert'); ?>
Obviously replace my username with yours. Now you’re done! Style it however you like with HTML and CSS.
Update:
If you’d like to show more then one tweet, here is an updated version of this function: http://jhnk.pastebin.com/5A4aXYTW


Cespur
July 17, 20091:22 pmNice one! I will probally be using this, thanks.
Green
August 3, 20099:03 pmVery helpful. looking at options currently.
human3rror
August 11, 20093:06 pmawesome.
webmack
August 15, 20095:54 pmit works the first time, btu when the cache time expires, the tweet stops showing. any way to fix this? I’m hosted on a windows server running IIS.
Andrea
September 10, 200910:56 pmcool, thanks… twitter's really hot right now, should get in the bus before it leaves!
shuks
October 4, 20096:52 pmThank you for this. very helpful indeed. quick question. Any way to refresh the tweet less than 1 hour? Thanks again.
Jo6891
October 5, 20094:06 pmFantastic! V. helpful, Thankyou!
inventory programs
October 16, 20099:06 amhmm.. good for you! ever since you are really great!
Patience
October 30, 20096:53 amThank you so much..I've spent hours to try and get this to work!…now to find some CSS help.
fast software
November 5, 20091:55 pmThanx for the useful info this blog is very educative.
@mandrill
November 12, 20091:43 pmIs there a way to add reply, retweet, follow and DM buttons/links to this in a similarly easy and user friendly fashion? Cos that would be great
Presentations Expert
November 20, 20095:59 pmNice sharing. Searching for this codes for long.
Marko
November 25, 20096:12 amsmall and very preaty peace of code
Thank you
Richard
January 10, 20107:07 amAwesome!!
Thanks
car
January 14, 20105:23 pmExcellent, been looking for this for a while, thanks!
Naturalpills
January 18, 20103:37 pmCoding, very good lines!!
Oil Heater
February 8, 201012:20 pmGreat piece of code, thanks for sharing it!
faydaliweb
February 23, 201010:01 amThanks for the codes.But ı think this can be done with plugin who dont wants to edit the templates
John Kolbert
March 18, 201010:33 pmYes, but I’m a developer. I like to do things myself rather then rely on plugins.
SJL Website Design
March 16, 20106:02 pmThanks for the great piece of code John, very simple solution compared to the javascript alternatives.
Fire Curtains
April 28, 20104:11 pmCheers for this, im gonna go put our twitter feed on our blog now!
Chris
April 30, 20105:57 amSweet! Thanks so much. This worked great for me. I needed something that would show the latest tweet per user, based on a custom field. Your 5 lines of code saved me hours of trying to find a plugin that could easily be changed to fit our needs. Copy, paste & 30 seconds of editing to throw in some variables & now we have complete functionality.
Thanks again!!
Brian
June 1, 20109:25 pmIs there a way to show more than 1 tweet and maybe add a time stamp? This truly is the best option for WP. Kudos, sir.
JP
June 25, 20103:32 pmnice article
rys
July 13, 20105:59 amyou can also refer to this site on how to display your latest tweets in twitter. with twitter API.
as easy as 1 2 3..
http://www.ryscript.co.cc/web/how-to-display-latest-tweets-using-javascript-and-twitter-api/
thanks..
justin
July 14, 20104:47 pmdoes this work with wordpress 3.0? I put the above code in my theme’s functions.php file and it breaks wordpress.
John Kolbert
July 28, 20103:59 amI’ve used this successfully in WP 3.0.
Sanjay
July 23, 20108:39 amThanks for the code. Is there any way to show more than 1 tweet?
John Kolbert
July 28, 20103:56 amHere’s an updated version that allows for multiple tweets:
http://jhnk.pastebin.com/5A4aXYTW