Title: Twitter Shortcode intergration
Last modified: August 19, 2016

---

# Twitter Shortcode intergration

 *  [wp_alba](https://wordpress.org/support/users/wp_alba/)
 * (@wp_alba)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/twitter-shortcode-intergration/)
 * Hi, Im trying to integrate my twitter function into wordpress via a shortcode,
   now everything works fine except it’s not allowing me to set a number of tweets
   to display and is only allowing the 1 tweet to be displayed.
 * Here’s the twitter function im using to pull the tweets;
    credit: [http://blog.spookyismy.name/2010/05/18/twitter-integration-class-using-php5-and-curl/](http://blog.spookyismy.name/2010/05/18/twitter-integration-class-using-php5-and-curl/)
 *     ```
       <?php
       class Twitter
       {
         public $tweets = array();
         public function __construct($user, $limit = 5)
         {
           $user = str_replace(' OR ', '%20OR%20', $user);
           $feed = curl_init('http://search.twitter.com/search.atom?q=from:'. $user .'&rpp='. $limit);
           curl_setopt($feed, CURLOPT_RETURNTRANSFER, true);
           curl_setopt($feed, CURLOPT_HEADER, 0);
           $xml = curl_exec($feed);
           curl_close($feed);
           $result = new SimpleXMLElement($xml);
           foreach($result->entry as $entry)
           {
               $tweet = new stdClass();
               $tweet->id = (string) $entry->id;
               $user = explode(' ', $entry->author->name);
               $tweet->user = (string) $user[0];
               $tweet->author = (string) substr($entry->author->name, strlen($user[0])+2, -1);
               $tweet->title = (string) $entry->title;
               $tweet->content = (string) $entry->content;
               $tweet->updated = (int) strtotime($entry->updated);
               $tweet->permalink = (string) $entry->link[0]->attributes()->href;
               $tweet->avatar = (string) $entry->link[1]->attributes()->href;
               array_push($this->tweets, $tweet);
           }
           unset($feed, $xml, $result, $tweet);
         }
         public function getTweets() { return $this->tweets; }
       }
       ?>
       ```
   
 * Here’s the shortcode im using
 *     ```
       <?php 
   
       function twitter_feed($atts, $content = null) {
   
       	extract(shortcode_atts(array(
       		"user"  => '',
       		"limit"  => ''
       	), $atts));
   
       	 $feed = new Twitter($user , $limit);
       $tweets = $feed->getTweets();
   
       foreach ($tweets as $tweet) {
   
       return '<ul><li>'. $tweet->content .' by <a href="http://twitter.com/'. $tweet->user .'">'. $tweet->author .'</a></li></ul>';
   
        }
   
       }
       add_shortcode("twitter", "twitter_feed");
   
       ?>
       ```
   
 * Example Shortcode
    `[twitter user="YourTwitterUserName" limit="5"]`
 * As I said above this code works fine apart from the tweet limit it, only ever
   pulls 1 tweet.
 * Now I’ve tried putting the code directly into the theme to see if it was a problem
   with the function but it works fine, so I must be doing something wrong in the
   shortcode. Any idea’s folks?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [likehate534](https://wordpress.org/support/users/likehate534/)
 * (@likehate534)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/twitter-shortcode-intergration/#post-1661819)
 * I would try using the shortcode:
    [twitter user=”YourTwitterUserName”**,** limit
   =”5″]
 * If that doesn’t work then no idea, it looks fine. I’m only suggesting that as
   a solution because you’ve said the shortcod ei would have used doesn’t work.
 *  Thread Starter [wp_alba](https://wordpress.org/support/users/wp_alba/)
 * (@wp_alba)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/twitter-shortcode-intergration/#post-1661962)
 * Thanks for the reply, it still doesn’t work though.
 * hopefully someone will have a solution sooner or later.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Twitter Shortcode intergration’ is closed to new replies.

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)
 * [functions](https://wordpress.org/support/topic-tag/functions/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)
 * [twitter](https://wordpress.org/support/topic-tag/twitter/)

 * 2 replies
 * 2 participants
 * Last reply from: [wp_alba](https://wordpress.org/support/users/wp_alba/)
 * Last activity: [15 years, 9 months ago](https://wordpress.org/support/topic/twitter-shortcode-intergration/#post-1661962)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
