How To Display Your Latest Tweet On Your WordPress Blog

Chris Creed / 12th March 2010

How To Display Your Latest Tweet On Your WordPress Blog How To Display Your Latest Tweet On Your WordPress Blog

Displaying your latest tweet on your site can be a good way of advertising your Twitter account (to potentially get more followers) and can help show visitors that you’re active and still working on the site.

In this WordPress video tip I’ll show you how easy it is to add your latest tweet to your WordPress blog. There are a range of plugins that can potentially do this for you, but it’s actually very simple to do this yourself through writing just a few lines of code.

I’ve also included some video notes and the source code below the video – and since this is a video tip on Twitter, I should probably advertise my account – you can follow at @cpcreed :-)

Quick note: If you have any issues with seeing the source code in this video you might want to watch it in HD and full screen mode.

Video Notes

In this tutorial I’m going to use a test installation of the Saburo WordPress theme (screenshot below) with a view to adding my latest tweet to the sidebar.

The first thing you need to do is open your functions.php file – add the following code to the bottom of that file and save the changes:

<?php
function displayLatestTweet($twitterID){
     include_once(ABSPATH.WPINC.'/rss.php');
     $latest_tweet = fetch_rss("http://search.twitter.com/search.atom?q=from:" . $twitterID . "&rpp=1");
     echo $latest_tweet->items[0]['atom_content'];
}
?>

This code is very simple – we’re basically creating a new function called “displayLatestTweet” which takes your Twitter username as an argument. We’re then fetching your latest tweet and storing it in a variable – the value of this variable is then displayed on the screen.

The next step is to open your sidebar.php file – add the following code:

<h2>Latest Tweet</h2>
<p><?php displayLatestTweet('cpcreed'); ?></p>

Again, this is very straightforward – we’re adding a title (“Latest Tweet”) and below that we’re calling the function we just created (displayLatestTweet) and passing in our Twitter user name (be sure to change the above code to use your own Twitter user name).

If you then view your site your latest tweet should now be displayed – you can see the final result in the Saburo theme below:

That’s it – very quick and simple to implement! I hope you found this tip useful and remember that you can follow on Twitter at @cpcreed.

Enjoy This Post? Please Consider Sharing :-)

  • Twitter
  • StumbleUpon
  • Facebook
  • Digg
  • del.icio.us
  • Reddit
  • Technorati

About The Author

Chris Creed

Hi there, I'm Chris and the Founder of Voosh Themes. I've been designing & developing websites for over 10 years and am interested in just about anything related to design. I also have a PhD in Computer Science (with a particular focus on Interaction Design) - you can follow me on Twitter at @cpcreed.

8 Comments

  1. March 13th, 2010 at 3:16 pm

    Cool thx :) This is my way how to display your latest tweet in own template: http://damek.eu/statusy-twittera-we-wlasnym-szablonie/

  2. April 22nd, 2010 at 8:27 pm

    Chris:

    The best and easiest method of displaying Tweets on Wordpress I’ve seen so far. I was wondering if you could help me with one problem, though…

    When the tweet displays on my blog, it spits out character entity codes.

    For example:
    ” I’m international now, baby! ”
    (turns into…)
    ” I'm international now, baby! ”
    on my blog page…

    Any recommendations on how to fix this?

    Thanks:)

    • April 23rd, 2010 at 9:04 am

      Hi Tone – I’ve not noticed this before – I’ll take a look into it.

  3. June 1st, 2010 at 6:45 pm

    There is only one problem… I can’t be found using Twitter Search! Any other way to get my twitter feed on my site?

  4. July 1st, 2010 at 12:08 am

    Cool! I have just got into blogs and tweeting and I am loving it. This tut has helped me get my tweets on my blog….I feel brainy! ;)

  5. Mia

    July 3rd, 2010 at 7:21 pm

    You are my hero :D ! – no seriously , I am now chiseling a slab of marble in your likeness :D
    Since the WP 3.0 upgrade – most plugins have become incompatible , and have caused serious issues w/ my theme ( and probably with many users themes out there ) ; I believe I have tried EVERY plugin and code out there for the past 3 days – and NONE of them have worked ! In fact : most of them cause my theme some serious issues . This is the only code which has worked like a charm :)

    Thank you so much Chris ! ( I will now head over to twitter & stalk you .. *cough..I mean add you ! ) :D

    M.

    • July 4th, 2010 at 9:52 am

      No problem Mia – glad it’s working :-) Always a pain when plugins become incompatible after updates!

  6. John

    July 5th, 2010 at 5:43 pm

    Thanks for this. Will this make links/hash marks clickable and open in a new window? If not, is there any way to implement it?

Trackbacks/Pingbacks

  1. March 13th, 2010 at 5:25 am

    [...] User News if (typeof Meebo == 'undefined') { Meebo=function(){(Meebo._=Meebo._||[]).push(arguments)}; (function(q){ var args = arguments; if (!document.body) { return setTimeout(function(){ args.callee.apply(this, args) }, 100); } var d=document, b=d.body, m=b.insertBefore(d.createElement('div'), b.firstChild); s=d.createElement('script'); m.id='meebo'; m.style.display='none'; m.innerHTML=''; s.src='http'+(q.https?'s':'')+'://'+(q.stage?'stage-':'')+'cim.meebo.com/cim/cim.php?network='+q.network; b.insertBefore(s, b.firstChild); })({network:'tripwiremagazine_fu72bi'}); }How To Display Your Latest Tweet On Your WordPress Blog [...]

  2. March 13th, 2010 at 12:55 pm

    [...] How To Display Your Latest Tweet On Your WordPress Blog [...]

  3. March 15th, 2010 at 2:05 am

    [...] How To Display Your Latest Tweet On Your WordPress Blog [...]

  4. March 19th, 2010 at 11:52 am

    [...] und diese auf eurem Blog automatisch anzeigen lassen wollt, solltet Ihr die Webseite “vooshthemes.com” besuchen. Hier findet Ihr eine kleine Anleitung wie man die letzten Twitter Feeds [...]

Leave a Reply