• Electric Studio Ltd.
  • Innovation Centre
  • 99 Park Drive, Milton Park
  • Oxfordshire, OX14 4RY
01235 436262 hello@electricstudio.co.uk


← Back to Blog

Use oAuth Twitter Feed for Developers to show your latest tweets in a list format with links

by ElectricStudio, December 16th 2013
Scroll down

oAuth Twitter Feed for Developers is a brilliant plugin to show your latest tweets on your WordPress website. Once installed and setup (you’ll need your OAuth Consumer Key, OAuth Consumer Secret, OAuth Access Token and OAuth Access Secret which can be found on your Twitter dashboard) you need to add a code snippet to your template.

The standard code is, where you’d need to replace the username, shows the last tweet with no links or formatting.

$tweets = getTweets(1, 'ElectricStudio', array('exclude_replies' => true, 'include_rts' => false));
foreach($tweets as $tweet){
echo $tweet['text'];

However, if you want to format them to be wrapped in a unordered list, UL, the code example below will pull in the last 3 tweets from the user ElectricStudio, and wrap it in UL/LI tags and include any embedded links for each tweet.

< ?php
$tweets = getTweets(3, 'ElectricStudio', array('exclude_replies' => true, 'include_rts' => false, 'include_entities' => true));
foreach($tweets as $tweet){
$tweet_text = $tweet["text"];
$tweet_text = preg_replace('/http:\/\/([a-z0-9_\.\-\+\&\!\#\~\/\,]+)/i', '<a href="http://$1" target="_blank">http://$1</a>', $tweet_text); //replace links
$tweet_text = preg_replace('/@([a-z0-9_]+)/i', '<a href="http://twitter.com/$1" target="_blank">@$1</a>', $tweet_text); //replace users
echo '<li>'.$tweet_text.'</li>';

Have you got any better suggestions on how to implement your latest tweets? Feel free to share.

  • This field is for validation purposes and should be left unchanged.