by Flo Preynat

June 12th 2013 – UPDATE: The method used in this post is no longer valid, Twitter having retired API v1, and rolled out API v1.1 yesterday.
Get it sorted out here.

In the course of my work of redesign of shoogledesigns.com (see teaser here), I have encountered a peculiar situation in trying to locate a quick and efficient way to display a number of my tweets on my website. Now, i’m not talking WordPress and plugins, but static html pages.

Embed tweets on a static website

I’ve been looking for a few tutos as it had been flipping ages I had needed to embed tweets into a static website, and funny enough, it took me quite a while to make it work again.

I wasn’t asking for much: no widgets, no third party apps, no 3-page tutorials and endless code to read. Just a few lines of jquery and a couple of variables to change is all I wanted.

Yet, this ended up being tough to find. It either didn’t work with the latest version of jquery at hand, didn’t display RT’s or didn’t display fuck all.

After a bit of work, i found some short code, and thought you may want to keep a copy of it, in case…

$(document).ready(function () {         
        
// Type in your twitter id here
    
var user = 'TWITTERID';
          
// How many Tweets do you want to display?
//Type in the number after &count=
// Do you wanna show RT's? include_rts= '0 for no' or '1 for yes'
 
    $.getJSON('http://api.twitter.com/1/statuses/user_timeline.json?screen_name=' + user + '&count=3&include_rts=1&callback=?', function(data)      {
          
        var tweet = "";
for (i = 0; i < data.length; i++) {
tweet += data[i].text + "

"; } tweet = tweet.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, function(url) { return ''+url+''; }).replace(/B@([_a-z0-9]+)/ig, function(reply) { return reply.charAt(0)+''+reply.substring(1)+''; }); // Give your tweets a home: here an element of id tweet (#tweet) $("#tweet").html(tweet); }); });

I’ve put an un-styled working version of this on my Github.
Download the files here.

My name is Flo Preynat and I am the freelance webdesigner and developer behind shoogle designs. I live in France and specialize in responsive web design. Give me a shoogle or get in touch with me on twitter.

Follow @shoogledesigns

Most Recent Posts

Special Recent Posts

Sip: a color picker refreshingly simple indeed

Sip: a color picker refreshingly simple indeed

July 10th, 2014

I've just discovered Sip, a color picker app for Mac users. "Just discovered" since it's been around[...]

Perch – the CMS that does not pollute your web design workflow

Perch - the CMS that does not pollute your web design workflow

July 7th, 2014

I have recently finished a project based on Perch, the clever 'little' CMS created by edgeofmyseat.c[...]

Responsive video code snippet

Responsive video code snippet

June 29th, 2014

More of a reminder than a pure detailed blogpost, this code snippet will be my go-to resource when I[...]

Project Naphta: a nifty extension to play with text embedded in images

Project Naphta: a nifty extension to play with text embedded in images

June 9th, 2014

We've all been there. You want to select a good chunk of text on a website, only to realise you can'[...]

Free photos for your web design projects

Free photos for your web design projects

June 4th, 2014

Nothing beats using a real professional photographer when working on a cool project. You can be the[...]

Comments

  1. Rob says:

    it’s rare that I find anyone else doing static websites and I was pleased to find yours. I grew up hand coding html in notepad and wrote my first book on the subject for a technical school back in 1995ish.

    now with speed requirements and a focus on author credibility and finally the release of twitter bootstrap… I’ve kinda gotten excited about hand coding websites again.

    this time… ranking for phrases aside, It’s awesome to get better and better and lightening website loads and speeding them up.

    I was looking for some light simple code that would display tweets in a static website. Voila. Thank you. I’ve actually added your rss to my Pulse reader on my phone

  2. Richard Schroder says:

    The straightforward copy n paste items you have produced delivered a result at this end in just a few moments.

    Have been hand-coding web projects since 1999 and your Twitter howto provides a superfast result.

    Thank you so much.

    best / Richard

  3. Chris says:

    Brilliantly simple solution. Thanks!

  4. Rachel Chorney says:

    This is just what I was looking for! Thanks. How would you modify the code to display all tweets with a specific hashtag?

  5. As I have stated it at the top of the post, the method used in this post is no longer valid, Twitter having retired API v1, and rolled out API v1.1 yesterday.

    More details here.