WordPress.org

Ready to get started?Download WordPress

Plugin Directory

Latest Tweets Widget

Latest Tweets widget compatible with the new Twitter API 1.1

Shortcodes

You can embed tweets in the body of your posts using a WordPress the shortcode [tweets].

To specify a different user's timeline add the user attribute.
To override the default number of 5 tweets add the max attribute, e.g:

[tweets max=10 user=timwhitlock]

Theming

For starters you can alter some of the HTML using built-in WordPress features.
See Widget Filters and Widgetizing Themes

CSS

This plugin contains no default CSS. That's deliberate, so you can style it how you want.

Tweets are rendered as a list which has various hooks you can use. Here's a rough template:

.latest-tweets {
    /* style tweet list wrapper */
}
.latest-tweets h3 {
    /* style whatever you did with the header */
}
.latest-tweets ul { 
    /* style tweet list*/
}
.latest-tweets li {
   /* style tweet item */
}
.latest-tweets .tweet-text {
   /* style main tweet text */
}
.latest-tweets .tweet-text a {
   /* style links, hashtags and mentions */
}
.latest-tweets .tweet-text .emoji {
  /* style embedded emoji image in tweet */ 
}
.latest-tweets .tweet-details {
  /* style datetime and link under tweet */
}

Custom HTML

If you want to override the default markup of the tweets, the following filters are also available:

  • Add a header between the widget title and the tweets with latest_tweets_render_before
  • Perform your own rendering of the timestamp with latest_tweets_render_date
  • Render plain tweet text to your own HTML with latest_tweets_render_text
  • Render each composite tweet with latest_tweets_render_tweet
  • Override the unordered list for tweets with latest_tweets_render_list
  • Add a footer before the end of the widget with latest_tweets_render_after

Here's an example of using some of the above in your theme's functions.php file:

add_filter('latest_tweets_render_date', function( $created_at ){
    $date = DateTime::createFromFormat('D M d H:i:s O Y', $created_at );
    return $date->format('d M h:ia');
}, 10 , 1 );

add_filter('latest_tweets_render_text', function( $text ){
    return $text; // <- will use default
}, 10 , 1 );

add_filter('latest_tweets_render_tweet', function( $html, $date, $link, array $tweet ){
    $pic = $tweet['user']['profile_image_url_https'];
    return '<p class="my-tweet"><img src="'.$pic.'"/>'.$html.'</p><p class="my-date"><a href="'.$link.'">'.$date.'</a></p>';
}, 10, 4 );

add_filter('latest_tweets_render_after', function(){
    return '<footer><a href="https://twitter.com/me">More from me</a></footer>';
}, 10, 0 );

Caching

Responses from the Twitter API are cached for 5 minutes by default. This means your new Tweets will not appear on your site in real time.

This is deliberate not only for performance, but also to avoid Twitter's strict rate limits of 15 requests every 15 minutes.

You can override the 300 second cache by using the latest_tweets_cache_seconds filter in your theme as follows:

This would extend the cache to 1 minute, which is the lowest value you should consider using on a live site:

add_filter('latest_tweets_cache_seconds', function( $ttl ){
    return 60;
}, 10, 1 );

This would disable the cache (not recommended other than for debugging):

add_filter('latest_tweets_cache_seconds', function( $ttl ){
    return 0;
}, 10, 1 );

Emoji

If you want to disable Emoji image replacement, you can filter the replacement callback function to something empty, e.g:

add_filter('latest_tweets_emoji_callback', function( $func ){
    return '';
} );
  • or to strip Emoji characters from all tweets, return your own replacement function that returns something else, e.g:

    add_filter('latest_tweets_emoji_callback', function( $func ){ return function( array $match ){ return ''; }; } );

Credits

Screenshot taken with permission from http://stayingalivefoundation.org/blog

Notes

Be aware of Twitter's display requirements when rendering tweets on your website.

Example code here uses PHP closures which require PHP>=5.3.0 and won't work on older systems.

Requires: 3.5.1 or higher
Compatible up to: 3.9.1
Last Updated: 2014-5-9
Downloads: 52,557

Ratings

5 stars
5 out of 5 stars

Support

1 of 3 support threads in the last two months have been resolved.

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

0,1,0
100,1,1 100,1,1
0,1,0
100,2,2
100,3,3