At the time of originally writing this article (March, 2016), Twitter had just renamed their Twitter favorites to "likes" (expressed by way of a little heart signal) in a puerile attempt at remaining relevant in a world dominated by Facebook. The change likely comes from the fact that the word 'favorite' isn't generally culturally-compatible because of the implied variations in translation, while a heart signal is a globally accepted symbol that transcends language. The change was just another to the platform in the months preceding to maintain relevance.
Note: While the code provided is functional, we've removed the examples as the website itself no longer requires Twitter support.
While the word "like" generally translates to "enjoy" in common language, it is inconsistent with the picture representation; likes (the heart) and favorites are very different things. I usually favorite tweets as a bookmark - not necessarily because I like them... and 'hearting' a tweet sends a very different message. If you look at my favorites you'll see tweets that I've often saved because I didn't like them. Changing what favorites are will change how they're used, and potentially alters all existing favorites as well.
Sometimes, however, it's nice to keep a list of your favorites 'likes' on your WordPress website as a resource for others, and they're a convenient way to bookmark tweets for your own reading. The WordPress shortcode on this page will render your favorites in a very basic manner.
The Result
For the purpose of this article I'll render just three favorites. To see a more comprehensive list, see this example page (50 results). To render the three likes below, I've used the shortcode of [twitterlikes user="MartyKhoury" num="3"]
. I could have omitted my username because I've listed it as a default in my code.
To display the likes of another use, substitute your own username for theirs. A maximum of 200 favorites can be returned in the one request. More details below.
Registering a Twitter Application
You must have a Twitter application registered. In doing so you'll create a $consumerkey
, $consumersecret
, $accesstoken
, and $accesstokensecret
that are all required in the shortcode function. You should refer to this video on setting up the necessary application on Twitter.
We're using Abraham Williams' TwitterOAuth library to assist with making the request. The library must be included at the top of your custom functions file (you'll need to reference the path to the
autoload.php
file).
The Code
Copy and paste the WordPress function into your theme's functions.php
file or, if you sensibly have one installed, your custom functions plugin.
The first function will convert the returned Twitter time into a more sensible format. Adjust as necessary by reference to PHP's date() function.
The second function converts text hashtags, username mentions, and URLs, into clickable links.
The last function takes a URL and snips it into two halves. We do this simply to preserve space. Alter the 35 to a maximum URL length.
Shortcode Attributes
The following shortcode attributes are available.
user
twitteruser
is the user for which to retrieve likes.num
cache
cache
is the amount of time to cache the data locally before making another request. Twitter rate limits 
PHP Function
Used outside of WordPress, the following may be used.
Usage is as follows:
A request for favorites is limited to your own account.
Considerations
- Liking articles, from Twitter
.
- More information on the
GET favorites/list
endpoint can be found here. There are a number of other attributes that could be applied but we'll reserve that functionality for our naked PHP function. The purpose of the shortcode was to make accessing data easy.
Download
Twitteroauth can be downloaded from Github , or via the source menu on the library website
.
Title: Display Twitter Favorites in WordPress or with PHP
Description: Retrieve Twitter Favorites (Likes) and Display in WordPress with Shortcode, or with PHP.
Download • Version 0.2, 1.4K, zip, Category: WordPress Shortcodes
PHP Code & Snippets, (1.5K)