Twitter Shortcode

This shortcode can be used to embed twitter widgets (embedded timelines, tweets), or to embed tweets or timelines directly in the page.

Widgets and Privacy

Twitter “widgets”, which essentially include a piece of javascript from twitter and a placeholder to hold the content, include embedded timelines, profiles, tweets and follow buttons. These widgets are styled like the twitter site and contain links back to twitter and various tools to allow users to follow, retweet, or interact in other ways with their service.

The script sets up the placeholder by dynamically writing an iframe in the page which includes the content directly from twitter. Using this method, you will enable the setting of cookies by twitter on the computers of your site visitors, so you will be opening a data channel to twitter for any user of your website who visits a page the widget is embedded on. These cookies include google analytics cookies (presumably to track people’s use of your website in twitter’s analytics package) and other cookies which identify you to twitter – these others will vary according to your current status on the twitter website (i.e. whether you are logged in or not). One cookie (called “guest_id”) has the capability of tracking users who are not registered on twitter, and can potentially log these users’ access to each page on your website to This is a “permanent” (2 years, refreshed on each visit) cookie which will then log a users access to other websites which use any of twitter’s widgets. There is a reasonably good explanation here:

It is not advisable to use “widgets” on a site which does not include:

  • a warning to users that you are allowing third parties to track their behaviour on your site
  • a mechanism to allow users to opt out of this
  • proper documentation on your privacy page about all the cookies set, what they do, and where to get further information

As these mechanisms aren’t currently implemented in the University theme, please do not use widgets on a site – you will be in breach of the EU cookie law if you do.

Twitter “Apps”

Twitter timelines can be embedded using a twitter “app” which has to be set up in the twitter user’s account. This method bypasses the twitter cookies by requesting data from twitter directly from the server, formatting it, and then sending it to the user’s browser. In this way, all the data gathering takes place on the server rather than in the client, and no cookies need to be set. You set up apps in twitter here:

Please note: this site may not work correctly in Internet Explorer 8 and earlier – use a different browser to set up your app.

When you create an app, use the site URL in both the Website box and the callback URL box.

Creating an app will give you two pieces of information (initially) – the Consumer key and Consumer secret. You will also need two additional pieces of information which you can get by clicking on the Create my access token button, and refreshing the page after a minute of so. The remaining two pieces of information, your Access Token and Access Token Secret will appear at the bottom of the page

Using the shortcode

To display your latest tweets (or tweet) using the shortcode, all you need is the four pieces of information from your app, and your twitter username. These are entered into the shortcode like this.

[tweets consumer_key="..." consumer_secret="..." access_token="..." access_token_secret="..." include_rts="0" user_id="UniversityLeeds"]

This example would display the latest 5 tweets from the @UniversityLeeds timeline (not including re-tweets).

Data from twitter is cached for a period of one hour (this is neccessary to prevent twitter from blocking access to the app on the grounds that it contravenes their fair use policy). Embedding a widget on the other hand would give you a real-time stream of tweets.

Shortcode options

General options

user_id or screen_name
The twitter username of the user’s timeline you want to embed.
[integer – default 20]
The number of tweets to display.
[boolean – default true]
Whether to include other user’s replies in the timeline (**not recommended**).
[boolean – default true]
Whether to include re-tweets in the timeline.

App options

One of the pieces of information you were given when you set up the twitter app.
One of the pieces of information you were given when you set up the twitter app.
One of the pieces of information you were given when you set up the twitter app.
One of the pieces of information you were given when you set up the twitter app.

Widget options

The ID of the Widget set up in your twitter account.
[string – either dark or light]
Use either the dark or light themes (default is to use the light theme).
[hexadecimal colour]
The colour you want links and icons to be in the widget.
The width of the widget in pixels.
The height of the widget in pixels.
The widget language is detected from the page, based on the HTML `lang` attribute of your content. You can also set the HTML `lang` attribute on the embed code itself.
A comma-separated list of user screen names as suggested followers to a user after they reply, Retweet, or favorite a Tweet in the timeline.
[string – default ‘assertive’]
ARIA is an accessibility system that aids people using assistive technology interacting with dynamic web content. Read more about ARIA on W3C’s website. By default, the embedded timeline uses the least obtrusive setting.