It’s fairly easy to hack an RSS feed of your tweets from Twitter into a WordPress page. It’s a two step process and all the coding is done in a new template page.
First of all go to your Twitter page and a web browser and look at the source code. From there you should see something that looks a little like ‘http://twitter.com/statuses/user_timeline/6156482.rss’ (this is my Twitter timeline feed RSS). Save this or get ready to insert this into the code later. Let’s move on to making this page.
Making the template page
To make my Twitter RSS feed page, I made a copy of page.php from my theme folder and renamed it to template-twitter.php.
For it to be used as a real template in the WordPress system I added this to the top of the code:
/*
* Template Name: Twitter Page
*/
?>
The final page as a regular template now looked like this:
/*
Template Name: Twitter Page
*/
?>
<div id="content">
<div>
<h2><a title="<?php the_title(); ?>" rel="bookmark" href="<?php the_permalink() ?>"></a></h2>
<p>Sorry, no posts matched your criteria.</p>
</div>
</div>
Adding the Twitter code
The code to produce the feed is really simple and there are many more ways of expanding upon it but for the sake of simplicity we let’s go with a plain unordered list of items. First of all we’d like to enclose our items in an unordered list and each Tweet will be a list item. Wrapped around this is he hyper link to the actual tweet on Twitter.
// inc feed.php so we can fetch the Twitter RSS
include_once(ABSPATH . WPINC . '/feed.php');
// make a feed object from the Twitter RSS
$twitterfeed = fetch_feed('http://twitter.com/statuses/user_timeline/6156482.rss');
// set max entries
$maxitems = $twitterfeed->get_item_quantity(10);
// build an array from 0 to $maxitems
$rss_items = $twitterfeed->get_items(0, $maxitems);
?>
<ul>
<?php
// some debugging in case you screw up with the RSS feed (or have no entries in the RSS)
if ($maxitems == 0)
echo '<li>No items.</li>';
else
// loop thru and display items from the RSS feed array
foreach ( $rss_items as $item ) : ?>
<li>
<a href="<?php echo $item->get_permalink(); ?>"
title="<?php echo 'tweeted ' . $item->get_date('j F Y | g:i a'); ?>">
<?php echo htmlentities($item->get_title()); ?></a>
<?php echo $item->get_date('F j Y | g:i a'); ?>
</li>
<?php endforeach; ?>
</ul>
Explanation of the code
include_once(ABSPATH . WPINC . '/feed.php');
This is a call to include the WordPress feed api so we can make use of the feed functionality (software reuse, amazing!)
$twitterfeed = fetch_feed('http://twitter.com/statuses/user_timeline/6156482.rss');
I added the comment here that we’d be making a feed object from the Twitter RSS. Pretty self explanatory. This is where you insert your Twitter RSS feed.
$maxitems = $twitterfeed->get_item_quantity(10);
This is the place to enter the number of items you’d like to display in your feed. Again, pretty self explanatory!
$rss_items = $twitterfeed->get_items(0, $maxitems);
?>
This is where we build out the array and tell it to start from zero items and count all the way up to the number of items specified previously.
echo '<li>No items.</li>';
If there aren’t any entries in the feed, this will help it be (somewhat) graceful and spit out a string to that effect.
// loop thru and display items from the RSS feed array
foreach ( $rss_items as $item ) : ?>
Assuming we have some feed entries, the code begins to step through each value with ‘foreach‘ and creates the array ‘$item’.
<?php echo htmlentities($item->get_title()); ?></a><br />
<?php echo $item->get_date('F j Y | g:i a'); ?>
The code above is the real meat of it all. This is the code that spits out items from the ‘$item’ array from the Twitter RSS feed. This block of code is all contained within a list item (‘<li>’). Within the ‘<a>’ tag you can see the ‘href’ attribute is output as ‘$item->getpermalink();’ as well as the ‘title’ attribute.
The anchor text is displayed by outputting ‘$item->get_title()’ and is cleaned up somewhat by the ‘htmlentities’ function.
At the end, the date is added in a similar way to how it is added in the ‘title’ attribute of the link and the ‘<li>’ list item is terminated.
<?php endforeach; ?>
</ul>
Finally, the foreach control structure is terminated and the unordered list is closed.
The complete code is here. You can save this and upload to your /wp-content/themes/THEME-NAME-HERE/.
Now to make the page in WordPress.
From here onwards it’s really easy. All we have to do is make a regular WordPress page and write any introduction paragraph explaining what that page is and then select the template.
Now, because WordPress is super hi tech these days, people can move around certain components of their working installation so you should be looking for something that allows you to select a template which is included in the ‘Attributes’ section (min is on the right hand side).
Here is a screenshot of what it looks like:

WordPress - choose a template
Of course, if you’ve made it to there, you need to choose the correct template, like this:

WordPress - choose a template from the dropdown
The end…
Write your paragraph blurb and make sure you’ve selected the twitter template and loot at your new page (mine looks like this).

This code do not work, I get:
Fatal error: Call to undefined method WP_Error::get_item_quantity() in …
Hi, not enough info there to determine the problem.
Hi Carlo,
Do you know of any way to combine my tweets with my blogposts in one page, sorted by timestamp? So that the tweets are automatically merged into the blogpost stream.
I hope that you understand what I’m hinting at.
– Niels
I understand what you’re saying but I’m not sure if Twitter and WordPress can work that way together.
In Twitter there are no tags, unless you tag the entry with a hashtag. I guess from there you could relate it to a group in WordPress.
Perhaps, check out the Twitter API and see what they have on offer.
Hi Carlos,
I’ve been hacking some things together and got it to work :-)
– Niels
Great. I was going to remake the twitter script but the twitter widget is great. No need as far as I can see form my own needs.