Easily add your latest tweets to your WordPress website

There are many Twitter plugins for WordPress but why not create your own ways of displaying your tweets with these 2 simple methods.

Method 1:

<?php
$username = “YOURTWITTERID”;
$prefix = “<h2>My latest tweets</h2>”;
// Suffix – some text you want display after your latest tweet. (Same rules as the prefix.)
$suffix = “”;
$feed = “http://search.twitter.com/search.atom?q=from:” . $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);
?>

Method 2:
Paste this into your functions.php

function wp_echoTwitter($username){
include_once(ABSPATH.WPINC.’/rss.php’);
$tweet = fetch_rss(“http://search.twitter.com/search.atom?q=” . $username . “&amp;amp;rpp=1″);
echo $tweet-&amp;gt;items[0]['atom_content'];
}

Then simply paste this where you want the tweet to display

<?php wp_echoTwitter(‘YOURTWITTERID’); ?>

Obviously replace YOURTWITTERID with yours and then style with CSS as you desire.

2 Comments + Add Comment

Leave a comment

You must be logged in to post a comment.