How to Display Your Twitter Posts on Your WordPress Blog

Published Saturday, March 22, 2008 @ 5:16 pm • 7 Responses

Alright, time for another “How’d-you-do-that-thing-on-your-site?” post. This question comes from the one and only Mr. Graham of ImJustCreative.com. In a recent email, Graham literally begged me to share my “secret recipe” for displaying my latest Twitter Tweets (wow, did I actually just say that?) right here on Perishable Press:

…Would be really really decent of you if you could let me know how to do it? Pretty please? How do you call the last twitter feed, what commands do you need etc?

In case you have no idea what we’re talking about here, scroll down to the bottom of any page on the site (using the current theme) and observe the savviness and sophistication of my latest Twitter post, updated automagically every fifteen minutes. Or, for those of you too lazy to “go there,” here is a screenshot demonstrating the perpetual Twitter display:

[ Screenshot: Perishable Tweets Displayed at Perishable Press ]

Amazing, isn’t it? I hope so, because it was terribly difficult to achieve. Not really, but I do enjoy sharing my tweets right here on my own site. It encourages me to keep active on Twitter and helps direct traffic to my Twitter account. Plus, it’s just a thrill to see it all “up in lights” and everything. Whatever though! We all know that Twitter Sucks! Okay, okay, enough song and dance, let’s get on with another fascinating tutorial, shall we..?

So, you want to display your “Twitter Tweets” (aaaarrrrggghhh!!!!) on your blog..

First, to do things my way (there are many others!), you will need each of the following:

  1. A WordPress-powered blog
  2. A you-powered Twitter account
  3. The amazing SimpleTwitter plugin
  4. The PHP cURL library installed on your server

Once you are down with all that, upload and install the SimpleTwitter plugin as per the instructions. Once installed, click on over to the SimpleTwitter Options tab in the WordPress Admin and customize the following settings:

  • Your Twitter username
  • The cache duration (amount of time between updates)

Your Twitter username is a no-brainer, and the cache time is simply the amount of time that should pass before the plugin checks for a fresh tweet. Even if you Twitter like every minute or so, it is best to use caution when choosing the cache interval. Have mercy on your server! For example, I use 15-minute intervals, but would increase that to 10 or even 5 (at the most!) if I were a more frequent Twitter tweeter (somebody KILL me!). Whatever, it’s up to you! After picking your nose settings, click the ‘ol “Update Options” button and call it good.

Part two: Sealing the deal — preparing your PHP for some serious tweets..

Everyone okay so far? At this point, we have all the required functionality in place; all that remains is to call the SimpleTwitter function and present it with some sort of (X)HTML markup. Hopefully, this won’t be too difficult.. ;)

Alright, open up your theme’s footer.php (or whatever) file and add the following code:

<p><?php if (function_exists('get_twitter_msg')) { get_twitter_msg(); } ?></p>

Save, upload, and check the results in a browser. If everything is working (i.e., you did everything correctly), you should see your latest Twitter post displayed near the bottom of the page. If nothing appears, try changing the plugin’s “cache interval” in the Admin options page. Change it to anything different and then save your changes. This should cause the plugin to make a new request for your latest tweet and display it accordingly. If even this doesn’t work, try posting a new tweet, adjusting/saving the settings (again), and wash rinse repeat a couple fo times until it “kicks in.” Honestly, it should work fine “out of the box,” with no problems whatsoever. It worked (and continues to work) great for me, but I mention the troubleshooting tips “just in case..”

Part three: a little CSS to make it all tweet..

After you get everything working, you will probably want to fine-tune your markup and/or CSS to suit your blog’s design. For this site, I wanted to spice things up a little bit by adding a Twitter icon to the left and linking the tweet to my Twitter account. Here is the (X)HTML markup (and requisite PHP) that I decided to use:

<div class="content">
	<p class="center"><span class="twitter"><a href="http://twitter.com/perishable" title="Twitter Sucks!" rel="nofollow"><?php if (function_exists('get_twitter_msg')) { get_twitter_msg(); } ?></a></span></p>
</div>

..and associated CSS styles:

div.content { 
	margin: 33px 0; 
	clear: both; 
	}
p.center { 
	text-align: center; 
	}
span.twitter {
	background: url(images/twitter.gif) no-repeat left center; 
	padding-left: 17px; 
	}

Oh, I know, there are better ways of doing this, but this is what I went with, so feel free to make it all better!  Of course, to see this code in action, I once again refer you to the bottom of any page of the current theme. Essentially, I have applied some modest vertical space, centered the contents of the paragraph (i.e., the link), and added the twitter icon ( [ Icon: Twitter Bird Thing ] ) to the left. And finally, I decided to “nofollow” the link to Twitter because I suck am trying to control sitewide external links.

Obviously, there are many possibilities when it comes to presenting Twitter posts on your own site, but I offer this method as a way to get your juices flowing. Who knows, you may even want to display your tweets somewhere other than your footer, like your sidebar or “About” page or something. Maybe use a different icon, bigger font — whatever!

Well okay, that about does it for this action-packed tutorial — have fun twittering those tweets you crazy twitterers! “Two tweets to the wind!!”

Next up..

In the next “How-to..” post, I finally get around to explaining the process used to create the coveted Perishable Press sun icon and logo. Stay tuned!


Dialogue

7 Responses Jump to comment form

1teddY

March 22, 2008 at 8:09 pm

Hey Jeff first of all HAPPY EASTER :) I just realised it’s Sunday. I think weekends are a blur to me because I usually sleep very late and wake up even later.

Twitter is a fun web application! I like it how the way they make it possible for bloggers and non-bloggers alike to update their current status and inform their friends about things they’re up to. Now the web is finally getting more personal (although a little spooky, like how Google enroaches into our privacy but hey, it’s fun!).

I’ve just created a Twitter account yesterday and tried to insert the my twitters into my blog. I’ve used Alex King’s plugin though - Twitter Tools. I hate myself for not being patient enough to wait another day to read your tutorial and decide on a simpler plugin :(

Simple Twitter sounds very simple and user-friendly! Although Twitter Tools may come jampacked with a little more functionality, the making-it-to-work part was frustating, so much so that I have to actually rollback for the older version due to issues with the prototype.js file.

Thanks for sharing, it’s another great tutorial. I’m definitely linking this, I hope you don’t mind!

P.S. I love this line: “Part three: a little CSS to make it all tweet..” it sounds so cute!

2Graham Smith

March 23, 2008 at 7:49 am

Ha ha.
Yes, tell the world how I begged mercilessly for information.

Well, you relented didn’t you? So it worked. Must try more often.

Your tutorials rock Mr J.

So now when you going to implement a Tumblr Blog? Hmmm? Well? I have seen it done and it looks great.

Me.

3Perishable

March 25, 2008 at 2:41 pm

Thanks for the feedback, teddY! I am glad you enjoyed the tutorial. You are absolutely right about Twitter Tools — it is one the most comprehensive Twitter plugins I have seen, allowing users to do just about anything with their Twitter posts. For me, I try to keep the processing overhead as low as possible, especially when it comes to WordPress plugins. It’s definitely a fine line between performance and functionality, but for the current incarnation of the site, simply displaying my Twitter tweets (there I go again!) was more than enough to serve all of my Twittering needs. But who knows, in the next theme evolution, I may wind up expanding the implementation. Okay, I’m just rambling now.. time to go eat some lunch! ;)

4Perishable

March 25, 2008 at 2:48 pm

Alright, alright.. one more comment before lunch — just for you, Mr. Graham! What, you didn’t appreciate being exposed for the lowly beggar you truly are? Shame, shame! ;) And, about all that “Tumblr Blog” nonsense, interestingly enough, someone just asked if I would design a custom, minimalist-style Tumblr theme. I like the idea and plan on looking into it for sure, but there wasn’t any begging involved, so who knows what will happen! ;)

5teddY

March 25, 2008 at 11:40 pm

I’ve tried the Twitter plugin you’ve linked and I find it simple :) it just displays a simple block of Twitter test, which totally fits your minimalistic design. Great job! And thanks for your reply!

6Teleken

July 20, 2008 at 8:43 am

I was looking for something like this all weekend. Thanks!

7Perishable

July 21, 2008 at 11:16 am

Happy to help, Teleken! :)

Subscribe to comments on this post


Share your thoughts..

TopRead official comment policy

Contact Perishable Press

  • Contact Jeff via form

Search Perishable Press

About Perishable Press

Perishable Press is the virtual playground of Jeff Starr — visionary, founder and lead developer of Monzilla Media, a small web and graphic design company in the lush desert oasis of Moses Lake, Washington. Perishable Press features articles and tutorials on many aspects of digital design..

Read more..

Perishable on Twitter

mmmm, dark chocolate..

Perishable on Tumblr

Tons of Firewalls

Tuesday, 7 October 2008, 1:45 am

Recently overheard on conservative talk radio (instructing listeners how to obtain a free promotional video from their new website):

“This website has tons and tons of firewalls, so you have to use your real email address to download the video..”

The Quiet Search Revolution

Monday, 6 October 2008, 12:15 pm

Just a thought.. As awesome as Google is these days, it would suck if they ended up owning the entire search-engine business. When they get to the point where all competition is impossible (due to their sheer size, financial resources, media influence, etc.), how many alternate search engines will have the resources for continuous improvement and top-quality search results? When this happens, we will have no choice but to do exactly what Google tells us to do.

As deeply ingrained as it is for everyone to instinctively and unthinkingly turn to Google for their search activity, it is time to leave a few alternate search tabs open for as much use as possible. Instead of using Google just because that’s what you always do, try your search on MSN, Yahoo, Ask, or any of the other independent search engines instead. Sharing traffic with other search engines is a nice, quiet way to keep the competitive spirit alive and well in the search-engine business.

Disappearing WordPress Posts

Wednesday, 1 October 2008, 7:50 pm

Today I experienced difficulties while trying to publish or even save new posts in WordPress. I would compose the post as usual, add all of the keywords, tags, meta tags, and so on, but as soon as I clicked the “Publish” or “Save” button, the post would just disappear from existence.

The weird thing is that during the drafting process, WordPress’ default auto-save feature showed that the post had been saved at expected intervals. Unfortunately, after trying to publish several different posts, WordPress showed absolutely no record of the posts ever being created. They simply vanished into thin air.

Fortunately, a little investigation revealed the culprit. If you should find yourself dealing with this same issue, here are some different things that you should try. First, re-upload fresh copies of your entire WordPress installation. I don’t know why exactly, but apparently various files can either go stale or completely disappear from the server. Overwriting or writing fresh files may do the trick.

If that doesn’t work, check your WordPress database for errors. In my case, a little investigation revealed that something had caused a couple of fatal errors in the wp_posts table. Fortunately, checking and repairing the table solved the issue.

Tumblr Battles

Wednesday, 1 October 2008, 5:30 pm

Please excuse the duplicate Tumbr posts.. seems there is no way to ping Tumblr to refresh/rebuild the RSS feed according to changes in post content. So, to resolve the issue I have discussed now like two or three times regarding paragraph elements and proper feed formatting, I have no choice but to repost a majority of my text posts.

This is necessary for the proper import and display of my Tumblr feed into WordPress. Currently, there are five items displayed at once, each styled according to proper inclusion of paragraph tags. Thus, whenever the Tumblr feed “forgets” to enclose single-paragraph posts with the proper tags, the result is an unstyled post entry displayed on my site.

Assuming that makes sense, you will please excuse my dust while I repost a few older entries in an attempt to reconstruct (the hard way) a properly formatted Tumblr feed.

More Optimization Measures

Wednesday, 1 October 2008, 5:27 pm

Another important step in improving the performance of my recent redesign involves the optimization of both CSS and JavaScript content. During development there were around 15 server requests for these two types of files, 10 JavaScript files and 5 CSS files. This was okay for my own use, but would not work for production purposes.

Optimizing these file types involves consolidation, compression, and caching. Consolidation of 10 JavaScript files into three is huge improvement. Now I deliver one JS file for the functionality of the site, one for Mint, and another for Analytics. Likewise for the stylesheets; after consolidation, a single stylesheet is delivered to all modern browsers. There are two additional stylesheets as well, but they are targeted at IE6 and mobile browsers and will not load elsewhere.

Once the files were consolidated as much as possible, it was time to optimize or “crunch” them. Using the sexy Flumpcakes CSS optimizer, I was able to reduce my stylesheets by around 25%. Likewise for JavaScript, I used xtreeme.com’s optimizer to shave an additional 20% off the size of my JS content.

Finally, once I had consolidated and compressed my JS and CSS files as much as possible, I wanted to further my optimization efforts by ensuring that these files were cached by the browser. By setting far-future Expires headers for everything but the statistical files, my site gains an additional performance boost by eliminating the need to reload preexisting content.

Read more on Tumblr..

Subscribe to Comments Recent Dialogue

  • Nyx: Happy to have helped! Love your site....
  • dockside: Hi i want to use this code on my blog. but not for all post. I want 3 or 4 full posts and then post in double column How?...
  • NZ Beats: Got it working using the following: http://www.nzbeats.com/?feed=rss2&category_name=album-review...
  • Paul: Holy crap, you just saved my A$$! Thank you!...
  • free games: Google have a content distribution network here http://code.google.com/apis/ajaxlibs/documentation/#AjaxLibraries where you ca...
  • free games: Found this (untested) for those that just want https For HTTPS: var pageTracker = _gat._getTracker("UA-XXXX-1"); pageTracker...
  • H5N1: The question is very hard. No way to solve it in only few words :) First of all you need a Linux. OK. But Linux it's only a Kerne...
  • gowers: wow, your theme is so great, I like it...
  • Eric Ferraiuolo: Like some people are commenting, a virtual solution is going to be the easiest to get going with the least number of issues. I would ...
  • Brent Terrazas: Thanks for the mention, I currently am running Ubuntu Server 8.04 on VMWare Fusion beta (it's a free beta download.. check it out fo...

Read more recent comments..