How To Add Twitter Feeds To WordPress Without Plugins (PHP)

Sean Davis

Sean is an engineer from Los Angeles, California. His primary focuses include internet security and web spam. Google+

23 Responses

  1. Kiearn Calvert says:

    Just to give the heads up on this.Twitter now require you to use Oauth library and their Json api to get feeds So this code is no longer valid. 🙁

  2. sidharthpkSid says:

    Whoa, it worked for me. I had tried the same method on another blog but unfortunately I didn’t add my username in the correct place, hence was getting an error. But since you highlighted the portion where which the editing , it did the job pretty well.

  3. Tommy says:

    Version 2 doesn’t seem to work? I can get Version 1 to work fine but when I try version 2 nothing is displayed other than the h2 tag. Suggestion?

  4. Brad says:

    Hey, thanks for this. I’ve implemented version 1 – is there a way to just make the twitter username clickable?



  5. Andre says:

    Fatal error: Call to undefined method WP_Error::get_item_quantity() in …
    I use wordpress 3.5, can you help me

    • Sean Doyle says:

      Version 1 seems to be fine, just tested it.

      The only reason I could think of such an issue would be if the code to include the blue color was copied and pasted on your site as well (span style=”color: #0000ff;”).

      If not, please copy and paste the code you used here so I can check it out.

  6. Francis Thibault says:

    I get a weird Warning: explode() [function.explode]: Empty delimiter

  7. In version 2, how can I get more then 1 tweet to show up?

    • Sean Doyle says:

      After all of the Twitter API changes I have not been able to repair the limit amount on version 2.
      Before, you were able to change the numeric on in the URL but it does not seem to work: $feed = “” . $username . “&rpp=*HERE*“;

      I will have to look further into this and/or create an additional post.

  8. Anonymous says:

    This didn’t work for me. When I pasted the code above (ver2) into my sidebar.php it just displays the raw php code in the sidebar.

  9. Dennis says:


    I looked for a lot of solutions and none of them seemed easy. This was as easy as it gets!

    THANK YOU!!!!

  10. desmoines says:

    Hi Sean–

    Is there a way to remove the twitter name so it only displays the tweet? Example: joesbar: The special today Clam Chowder.

    Is there a way that is only displays the special today…. and not joesbar?


    • Sean Doyle says:

      Add your Twitter handle to this code. Change text before and after tweet to whatever you wish or remove them/leave blank if you don’t want anything.

      < ?php
      $username = "Twitter handle here";
      $prefix = "Text Before Tweet";
      $suffix = "Text After Tweet";
      $feed = "" . $username . "&rpp=1";
      function parse_feed($feed) {
          $stepOne = explode("", $feed);
          $stepTwo = explode("", $stepOne[1]);
          $tweet = $stepTwo[0];
          $tweet = str_replace("<", "< ", $tweet);
          $tweet = str_replace(">", ">", $tweet);
          return $tweet;
      $twitterFeed = file_get_contents($feed);
          echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);
  11. Dustin van Zyl says:

    Thanks, this is a great hack which doesn’t degrade any other php even when using in main content areas (unlike most)
    Would it be possible to also fetch my twitter avatar.
    and would it be possible to style the fetched content?

  12. maffei says:

    Super basic question:

    I want to only display the text of the single, most current tweet, and not as a hyperlink. I’ve managed to get it to not be a hyperlink, but how do I get rid of the twitter handle prefix? Right now, the display is “• (twitter handle): (twitter message)”. Ideally, I’d eliminate the list bullet and the twitter handle. Thanks in advance.

    • Sean Doyle says:

      The list bullets will show on themes where appropriate, they are generally added to display permalinks on a single line.

      I apologize but I do not have the correct line to remove the Twitter handle, but if I come across it I will let you know.

      All that would need to change is < ?php echo $item->get_title(); ?>

      get_title() grabs the (twitter handle): (twitter message) as you stated.

Leave a Reply

Your email address will not be published.