If you have been using the un-maintained Twitter for WordPress plugin, or likely several other Twitter wordpress plugins, you might have noticed that your tweets were no longer displaying on your website. In the case of the Twitter for WordPress plugin, you would probably have seen the “No public Twitter messages.”
Back when this plugin broke last time, due to a change to WordPress’s RSS API, I wrote a post to do a quick fix, but mentioned that this was only temporary, as Twitter was updating their API.
Well, that time has come and as of about a month ago, Twitter has depreciated their old API in favor of API v1.1.
One big change is that this makes it a bit more difficult to just display tweets on your website, as you can no longer just grab the User Timeline RSS as you did in the past via a URL. Instead, you need to setup an Application within Twitter.
Fortunately, this is not too difficult and I have created a simple Twitter Plugin for wordpress to display a user’s tweets.
In order for the Twitter WordPress Plugin, it is necessary to create a new application through Twitter. This is pretty straightforward and the steps are described below.
You will need the information from step #5 when setting up the plugin for first use in WordPress.
The above images show the setup required via Twitter steps #3 and #5 below.
There are several ways to style the plugin. A default style is included in the plugin folder in the css/ folder. This style is added to the pages and is quite basic, but could be edited to change the style.
You could also override the style in your themes style.css file, as well as passing the shortcode arguments ‘css_id’ or ‘css_class’ .
This plugin makes use of the TwitterOAuth Library, written by Abraham Williams. The actual code to get the tweets is fairly straightforward:
$twitter_connection = new TwitterOAuth($consumer_key, $consumer_secret,$oauth_token, $oauth_secret ); $retrieved_tweets = $twitter_connection->get('statuses/user_timeline', array('count'=>$number_of_tweets, 'include_rts'=>$include_retweets));
The styling and output is controlled by the following for loop in the function, which is also used to display the shortcode:
foreach ( $retrieved_tweets as $tweet_index => $tweet ) { $tweet_text = $tweet->text; $tweet_link = $tweet_link_base.$tweet->id; if($time_format != -1) $tweet_time = " - ".date($time_format, strtotime($tweet->created_at)); else $tweet_time = ''; $tweet_body .= '<li id="kcr_st_tweet_{$tweet_index}">'; if ($args['hyperlink'] == '1') $tweet_text = kcr_st_add_hyperlinks($tweet_text); if ($args['hyperlink_users'] == '1') $tweet_text = kcr_st_parse_users($tweet_text); if($args['link_to_tweet'] == '1') $tweet_text .= '<a href="'.$tweet_link.'" class="kcr_st_link"></a>'; $tweet_body.="{$tweet_text}{$tweet_time}</li>"; }
If you have any issues, concerns, or comments, please drop me a message below. This solution will likely require a bit of customization, mostly in regards to styling, although the date format could be improved. I am open to suggestions on a default style. It is meant more as a base to display tweets, with the understanding that you will likely need to do some work to get the styling right. However, it should work well to display your recent tweets.
If you would like help customizing and installing it for your site, please contact me or give me a call and I would be happy to set it up for you.
Add a Comment