Get FREE lessons from "Hack It Easy Hacking Course"

Enter your email and instantly receive the lessons in your inbox for free

Wednesday, July 28, 2010

Display your latest tweet without a plug-in

8 in 15 Useful Twitter Hacks and Plug-Ins For WordPressIf people like your blog, they would probably also enjoy your tweets. Displaying your latest tweets on your WordPress blog is a good way to gain new subscribers. A plug-in can do that, but for such a simple task, I prefer a hack. This one grabs your latest tweet and displays it on your blog.
This ready-to-use code can be pasted anywhere in your theme files. Just don’t forget to change the value of the $username on line 4. The $prefix and $suffix variable can be used to insert a title, and the div element can be used for further CSS styling.
// Your twitter username.
$username = "TwitterUsername";

// Prefix - some text you want displayed before your latest tweet.
// (HTML is OK, but be sure to escape quotes with backslashes: for example href=\"link.html\")
$prefix = "

My last Tweet

"; // Suffix - some text you want display after your latest tweet. (Same rules as the prefix.) $suffix = ""; $feed = "" . $username . "&rpp=1"; function parse_feed($feed) { $stepOne = explode("", $feed); $stepTwo = explode("", $stepOne[1]); $tweet = $stepTwo[0]; $tweet = str_replace("<", "<", $tweet); $tweet = str_replace(">", ">", $tweet); return $tweet; } $twitterFeed = file_get_contents($feed); echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix); ?>
Save the file, and your latest tweet is displayed on your blog. Nice, huh?



   First Name:
* Your Email Address:


Twitter Delicious Facebook Digg Stumbleupon Favorites More