Written by me@grafxflow
11 Mar, 2013
19
4,927
Due to Twitter stopping their RSS feed I had to go down the Twitter API route. So here is how to set up a Twitter App and output the JSON feed into WordPress using the plugin oAuth Twitter Feed for Developer.
First lets do the ground work for the app creation at twitter:
1. Login at dev.twitter.com. If you already have a twitter account it should work here.
2. Next go to the dropdown and choose my "My applications".

3. Then select "Create a new application".

4. Now give your app a "Name", "Description" and your "Website" url that will be used for the feed. Then agree to the terms and conditions at the bottom. Note: The Apps name must be unique and not used by anybody else - either way Twitter will tell you this.

5. Now you will be taken to the "Details" tab of your new app. You can create your own access token but for ease of use I select choose "Create my access token".

6. Twitter will generate your apps access token.

7. Now lets add an icon to our twitter app by choosing the "Settings" tab and then scroll down to "Application icon" and upload your icon.


8. Now select the "OAuth tool" tab which will show the "OAuth settings" - we will be copying this information into WordPress. One thing to say is don't share this info with anybody!

9. Now go back into WordPress and install the following plugin oAuth Twitter Feed for Developers. Then in admin choose Settings -> Twitter Feed Auth and copy the twitter settings into the appropriate textfield on the form. Then "Save Changes".

9. Now you want to output the Twitter (JSON) feed, so here is an example to show your latest 2 feeds on the website header. Still in WordPress admin go to "Appearance -> Editor" and select the "header.php" on the right. Depending on your theme you will need to decide its placement and styling. Quick Note: By default the plugin checks the Twitter feed every hour so your Tweets may not appear straight away. This time can be changed but I would keep the default setting - if Twitter gets too many hits it stops the feed from being read.
UPDATE: A much more detailed example of code can be found here Example code to layout tweets
<?php
// Extracts all the urls and twitter users as links //
// Thanks to http://jamiebicknell.tumblr.com/post/413464002/php-to-convert-links-mentions-and-hashtags for the autoConvert function //
function autoConvert($text) {
$text = preg_replace("/((http(s?):\/\/)|(www\.))([\w\.]+)([a-zA-Z0-9?&%.;:\/=+_-]+)/i", "<a href='http$3://$4$5$6' target='_blank'>$2$4$5$6</a>", $text);
$text = preg_replace("/(?<=\A|[^A-Za-z0-9_])@([A-Za-z0-9_]+)(?=\Z|[^A-Za-z0-9_])/", "<a href='http://twitter.com/$1' target='_blank'>$0</a>", $text);
$text = preg_replace("/(?<=\A|[^A-Za-z0-9_])#([A-Za-z0-9_]+)(?=\Z|[^A-Za-z0-9_])/", "<a href='http://twitter.com/search?q=%23$1' target='_blank'>$0</a>", $text);
return $text;
}
// Number of tweets to show //
$number_of_tweets = 2;
// Your twitter username //
$tweets_screename = 'twitteruser';
$tweets = getTweets($number_of_tweets, $tweets_screename, $optional_array_of_any_additional_twitter_api_parameters);
// Output the Twitter results //
echo '<div id="twitter_feed_holder">';
echo '<h1>'.$tweets_screename.' @ twitter feed. . .</h1>';
foreach($tweets as $tweet) {
// Convert the date format //
$date_from_twitter = strtotime($tweet['created_at']);
echo '<p><span class="twitter-bullet"><a href="https://twitter.com/'.$tweets_screename.'/status/'.$tweet['id_str'].'" target="_blank">#</a> </span>'.autoConvert($tweet['text']).' <span>'.date('j M, Y', $date_from_twitter).'</span></p>';
}
echo '</div>';
?>
17 Mar, 2008
24 Nov, 2013
30 Apr, 2017
I am a Full-stack Developer who also started delving into the world of UX/UI Design a few years back. I blog and tweet to hopefully share a little bit of knowledge that can help others around the web. Thanks for stopping by!
Follow20 May, 2025
11 Jul, 2023
Views: 173,235
Views: 90,690
Views: 89,819
Views: 64,149
19 Response