Display Most Recent Tweet in WordPress

Twitter is getting very famous among bloggers. Many bloggers are now displaying their most recent tweet on their blog. If you want to display your most recent tweet on your blog simply place this code where you want to display it in your WordPress theme.
01
02
$username = “TwitterUsername”; // Your twitter username.
03
$prefix = “”; // Prefix some text you want displayed before your latest tweet.
04
$suffix = “”; // Suffix some text you want display after your latest tweet.
05
$feed = “http://search.twitter.com/search.atom?q=from:” . $username . “&rpp=1″;
06

07
function parse_feed($feed) {
08
$stepOne = explode(““, $feed);





09





$stepTwo = explode(“

“, $stepOne[1]);
10
$tweet = $stepTwo[0];
11
$tweet = str_replace(“<_ _="_" tweetbr="tweetbr">12





$tweet = str_replace(“>”, “>”, $tweet);





13





return $tweet;





14





}





15











16





$twitterFeed = file_get_contents($feed);





17





echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);





18





?>





e





Make sure to change the username in the first line.