You can use the Twitter Feed API to easily render tweets using PHP. The API features 3 main functions, one for each type of tweets display method (static, scrolling and sliding).

NOTE: If your are getting an error saying that you didn’t provide the Twitter tokens (and you did), then you’ve accessed the API too early. Try hooking to a later action.

Static Tweets

TwitterFeed\static_tweets( $options )

This function makes a call to Twitter REST API and returns an HTML formatted representation of the data returned. The data is displayed as static tweets.

Parameters

$options (array) an associative array with the following keys:

  • user (string) The user name.
  • count (string) The number of tweets.
  • replies (boolean) True/false whether to include replies.
  • retweets (boolean) True/false whether to include retweets.
  • resource (string) The type of twitter resource. One of the available resource types (see available option values).
  • id (string) The tweet’s id (only applicable for the single resource type).
  • list (string) The name of the list (only applicable for the list resource type).
  • query (string) The search query (only applicable for the search resource type).
  • skin (string) The tweet skin. One of the available skins (see available option values).
  • show (array) List of tweet assets to show. One or more of the available assets (see available option values).

Return Value

(string) The HTML formatted representation of the tweets.

Example call

<?php 
echo TwitterFeed\static_tweets(array(
    'user'      =>  'askupasoftware',
    'count'     =>  1,
    'replies'   =>  true,
    'retweets'  =>  true,
    'resource'  =>  'usertimeline',
    'id'        =>  null,
    'list'      =>  null,
    'query'     =>  null,
    'skin'      =>  'default',
    'show'      =>  array('username','screenname','avatar','time','actions','media')
));

Example Result

<!-- Static Tweets -->
<div class="atf-object atf-static-tweets atf-skin-default atf-direction-ltr">
  <div class="atf-inner-wrapper">
    <div class="atf-tweet-wrapper">
      <time class="atf-tweet-time" datetime="2016-05-02T04:12:47+00:00" title="Tweet Time">
        2 days ago </time>
      <div class="atf-user-card">
        <img src="https://pbs.twimg.com/profile_images/645828743487815680/4tH3dAYT_normal.png" width="32" height="32" alt="Askupa Software's Twitter avatar">
        <div class="atf-screen-name">
          <span>Askupa Software</span>
          <br>
          <a href="https://twitter.com/AskupaSoftware" target="_blank" dir="ltr">@AskupaSoftware</a>
        </div>
      </div>
      <p class="atf-tweet-text">We've released <a href="http://twitter.com/search?q=%23wordpress" class="preg-links" target="_blank">#wordpress</a> dynamic <a href="http://twitter.com/search?q=%23css" class="preg-links" target="_blank">#css</a> v1.0.4 with support for CSS minification.
        Download it for free on <a href="https://wordpress.org/plugins/wp-dynamic-css/" class="preg-links" target="_blank">wordpress.org/plugins/wp-dynamic-css/</a> <a href="http://twitter.com/search?q=%23php" class="preg-links" target="_blank">#php</a></p>
      <ul class="atf-tweet-actions">
        <li>
          <a href="https://twitter.com/intent/tweet?in_reply_to=726987778127355904" class="reply-action atf-web-intent" title="reply" style="position: relative;"><i class="fa fa-reply"></i><span class="screen-reader-text">reply</span></a>
        </li>
        <li>
          <a href="https://twitter.com/intent/retweet?tweet_id=726987778127355904" class="retweet-action atf-web-intent" title="retweet" style="position: relative;"><i class="fa fa-retweet"></i><span class="screen-reader-text">retweet</span> 1</a>
        </li>
        <li>
          <a href="https://twitter.com/intent/favorite?tweet_id=726987778127355904" class="favorite-action atf-web-intent" title="favorite" style="position: relative;"><i class="fa fa-heart"></i><span class="screen-reader-text">favorite</span> 1</a>
        </li>
      </ul>
    </div>
  </div>
</div>

Scrolling Tweets

TwitterFeed\scrolling_tweets( $options )

This function makes a call to Twitter REST API and returns an HTML formatted representation of the data returned. The data is displayed as scrolling tweets.

Parameters

$options (array) an associative array with the following keys:

  • user (string) The user name.
  • count (string) The number of tweets.
  • replies (boolean) True/false whether to include replies.
  • retweets (boolean) True/false whether to include retweets.
  • resource (string) The type of twitter resource. One of the available resource types (see available option values).
  • id (string) The tweet’s id (only applicable for the single resource type).
  • list (string) The name of the list (only applicable for the list resource type).
  • query (string) The search query (only applicable for the search resource type).
  • skin (string) The tweet skin. One of the available skins (see available option values).
  • scroll_time (number) The duration of each scroll in seconds.

Return Value

(string) The HTML formatted representation of the tweets.

Example call

<?php 
echo TwitterFeed\scrolling_tweets(array(
    'user'       =>  'askupasoftware',
    'count'      =>  2,
    'replies'    =>  true,
    'retweets'   =>  true,
    'resource'   =>  'usertimeline',
    'id'         =>  null,
    'list'       =>  null,
    'query'      =>  null,
    'skin'       =>  'default',
    'scroll_time'=>  2
));

Example Result

<!-- Scrolling Tweets -->
<div class="atf-object atf-scrolling-tweets atf-skin-default atf-direction-" data-scroll-time="2">
  <div class="atf-inner-wrapper">
    <div class="atf-tweet-wrapper" style="display: block;">
      <div class="atf-tweet-text">
        <p style="left: 0px;">
          <span>Askupa Software: </span> Major Vulnerability in Freshdesk – Results from a recent Wordfence Red Team Exercise <a href="https://www.wordfence.com/blog/2016/05/freshdesk-vulnerability-red-team-exercise/" class="preg-links" target="_blank">www.wordfence.com/blog/2016/05/freshdesk-vulnerability-red-team-exercise/</a>          via @<a href="http://twitter.com/wordfence" class="preg-links" target="_blank">wordfence</a> </p>
      </div>
      <time class="atf-tweet-time" datetime="2016-05-03T20:56:23+00:00" title="Tweet Time">
        May 3, 2016 </time>
    </div>
    <div class="atf-tweet-wrapper" style="display: none;">
      <div class="atf-tweet-text">
        <p style="left: 0px;">
          <span>Askupa Software: </span> We've released <a href="http://twitter.com/search?q=%23wordpress" class="preg-links" target="_blank">#wordpress</a> dynamic <a href="http://twitter.com/search?q=%23css" class="preg-links" target="_blank">#css</a>          v1.0.4 with support for CSS minification. Download it for free on <a href="https://wordpress.org/plugins/wp-dynamic-css/" class="preg-links" target="_blank">wordpress.org/plugins/wp-dynamic-css/</a> <a href="http://twitter.com/search?q=%23php"
          class="preg-links" target="_blank">#php</a> </p>
      </div>
      <time class="atf-tweet-time" datetime="2016-05-02T04:12:47+00:00" title="Tweet Time">
        May 2, 2016 </time>
    </div>
  </div>
</div>

Sliding Tweets

TwitterFeed\sliding_tweets( $options )

This function makes a call to Twitter REST API and returns an HTML formatted representation of the data returned. The data is displayed as sliding tweets.

Parameters

$options (array) an associative array with the following keys:

  • user (string) The user name.
  • count (string) The number of tweets.
  • replies (boolean) True/false whether to include replies.
  • retweets (boolean) True/false whether to include retweets.
  • resource (string) The type of twitter resource. One of the available resource types (see available option values).
  • id (string) The tweet’s id (only applicable for the single resource type).
  • list (string) The name of the list (only applicable for the list resource type).
  • query (string) The search query (only applicable for the search resource type).
  • skin (string) The tweet skin. One of the available skins (see available option values).
  • slide_dir (string) The slide direction. One of 'up', 'down', 'left', 'right', 'random'
  • slide_duration (number) The slide duration in seconds.
  • show (array) List of tweet assets to show. One or more of the available assets (see available option values).

Return Value

(string) The HTML formatted representation of the tweets.

Example call

<?php 
echo TwitterFeed\sliding_tweets(array(
    'user'          => 'askupasoftware',
    'count'         => 2,
    'replies'       => true,
    'retweets'      => true,
    'resource'      => 'usertimeline',
    'id'            => null,
    'list'          => null,
    'query'         => null,
    'skin'          => 'default',
    'slide_dir'     => 'left',
    'slide_duration'=> 2,
    'show'          =>  array('username','screenname','avatar','time','actions','media')
));

Example Result

<!-- Sliding Tweets -->
<div class="atf-object atf-sliding-tweets atf-skin-default atf-direction-ltr" data-slide-dir="left" data-slide-duration="2" style="height: 79px;">
  <div class="atf-tweet-padder" style="display: block; left: 1098.48px;">
    <div class="atf-tweet-wrapper">
      <time class="atf-tweet-time" datetime="2016-05-03T20:56:23+00:00" title="Tweet Time">
        21 mins ago </time>
      <div class="atf-user-card">
        <img src="https://pbs.twimg.com/profile_images/645828743487815680/4tH3dAYT_normal.png" width="32" height="32" alt="Askupa Software's Twitter avatar">
        <div class="atf-screen-name">
          <span>Askupa Software</span>
          <br>
          <a href="https://twitter.com/AskupaSoftware" target="_blank" dir="ltr">@AskupaSoftware</a>
        </div>
      </div>
      <p class="atf-tweet-text">Major Vulnerability in Freshdesk – Results from a recent Wordfence Red Team Exercise <a href="https://www.wordfence.com/blog/2016/05/freshdesk-vulnerability-red-team-exercise/" class="preg-links" target="_blank">www.wordfence.com/blog/2016/05/freshdesk-vulnerability-red-team-exercise/</a>        via @<a href="http://twitter.com/wordfence" class="preg-links" target="_blank">wordfence</a></p>
      <ul class="atf-tweet-actions">
        <li>
          <a href="https://twitter.com/intent/tweet?in_reply_to=727602727140741120" class="reply-action atf-web-intent" title="reply" style="position: relative;"><i class="fa fa-reply"></i><span class="screen-reader-text">reply</span></a>
        </li>
        <li>
          <a href="https://twitter.com/intent/retweet?tweet_id=727602727140741120" class="retweet-action atf-web-intent" title="retweet" style="position: relative;"><i class="fa fa-retweet"></i><span class="screen-reader-text">retweet</span> 0</a>
        </li>
        <li>
          <a href="https://twitter.com/intent/favorite?tweet_id=727602727140741120" class="favorite-action atf-web-intent" title="favorite" style="position: relative;"><i class="fa fa-heart"></i><span class="screen-reader-text">favorite</span> 0</a>
        </li>
      </ul>
    </div>
  </div>
  <div class="atf-tweet-padder" style="display: block; left: -500.52px;">
    <div class="atf-tweet-wrapper">
      <time class="atf-tweet-time" datetime="2016-05-02T04:12:47+00:00" title="Tweet Time">
        2 days ago </time>

      <div class="atf-user-card">
        <img src="https://pbs.twimg.com/profile_images/645828743487815680/4tH3dAYT_normal.png" width="32" height="32" alt="Askupa Software's Twitter avatar">
        <div class="atf-screen-name">
          <span>Askupa Software</span>
          <br>
          <a href="https://twitter.com/AskupaSoftware" target="_blank" dir="ltr">@AskupaSoftware</a>
        </div>
      </div>
      <p class="atf-tweet-text">We've released <a href="http://twitter.com/search?q=%23wordpress" class="preg-links" target="_blank">#wordpress</a> dynamic <a href="http://twitter.com/search?q=%23css" class="preg-links" target="_blank">#css</a> v1.0.4 with support for CSS minification.
        Download it for free on <a href="https://wordpress.org/plugins/wp-dynamic-css/" class="preg-links" target="_blank">wordpress.org/plugins/wp-dynamic-css/</a> <a href="http://twitter.com/search?q=%23php" class="preg-links" target="_blank">#php</a></p>
      <ul class="atf-tweet-actions">
        <li>
          <a href="https://twitter.com/intent/tweet?in_reply_to=726987778127355904" class="reply-action atf-web-intent" title="reply" style="position: relative;"><i class="fa fa-reply"></i><span class="screen-reader-text">reply</span></a>
        </li>
        <li>
          <a href="https://twitter.com/intent/retweet?tweet_id=726987778127355904" class="retweet-action atf-web-intent" title="retweet" style="position: relative;"><i class="fa fa-retweet"></i><span class="screen-reader-text">retweet</span> 1</a>
        </li>
        <li>
          <a href="https://twitter.com/intent/favorite?tweet_id=726987778127355904" class="favorite-action atf-web-intent" title="favorite" style="position: relative;"><i class="fa fa-heart"></i><span class="screen-reader-text">favorite</span> 1</a>
        </li>
      </ul>
    </div>
  </div>
</div>

Available Option Values

Option Name Available Value(s) Notes
resource 'usertimeline'
'hometimeline'
'mentions'
'retweets'
'list'
'search'
'favorites'
'single'
Only the User Timeline resource type is supported in the demo version
skin 'default'
'simplistic'
'futuristic'
'talk-bubble'
'led-screen'
Only the default skin is supported in the demo version. The led-screen skin can only be used for scrolling tweets.
show 'username'
'screenname'
'avatar'
'time'
'actions'
'media'

Spread the word about Twitter Feed!