getButterfly Logo getButterfly

I’ve always wanted to show my last twits in my sidebar. I’ve recently found out how. Here’s a quick tutorial:

Place the following code in your sidebar. Remember to style it properly and replace the username:

// Your twitter username.
$username = "butterflymedia";
// Prefix - some text you want displayed before your latest tweet.
$prefix = "<h3>My last Tweet</h3>";
// 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("<content type=\"html\">", $feed);
    $stepTwo = explode("</content>", $stepOne[1]);
    $tweet = $stepTwo[0];
    $tweet = str_replace("&lt;", "<", $tweet);
    $tweet = str_replace("&gt;", ">", $tweet);
    return $tweet;
$twitterFeed = file_get_contents($feed);
echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);

Subscribe to getButterfly Blog

Once a week or so we send an email with our best content. We never bug you, we just send you our latest piece of content.

If you found any value in this post, agree, disagree, or have anything to add - please do. I use comments as my #1 signal for what to write about. Read our comment policy before commenting! Comments such as "Thank you!", "Awesome!", "You're the man!" are either marked as spam or stripped from URL.

6 thoughts on “How To Add Latest Twits To Your Sidebar

  1. thank you for a code I searched him long

  2. Fantastic post! this post have more informative code which more useful for me so thanks for given this.

  3. It sure does help when information gets shared by folks like you. Especially for non-coders like me! I still don’t really use twitter, but am starting to sit up and take notice, because the hype has to have some form of substance behind it, especially when it gets touted as the next Google!

  4. thanks for this post i knew about it already but it will be so helpful for new blogger.

  5. I’m glad you all find this information helpful. I’ll try to post more tutorials in the future.

Leave a Reply

Your email address will not be published. Required fields are marked *