Skip to content
This repository was archived by the owner on Apr 7, 2022. It is now read-only.

Embedded Collection Timeline

Ben Ward edited this page Dec 11, 2017 · 1 revision

The Twitter plugin for WordPress supports embedding the a curated set of Tweets by pasting a Twitter collection URL into the WordPress post editor or by customizing a [twitter_collection] or [twitter_grid]WordPress shortcodes for a vertical or grid layout of Tweets respectively. WordPress users capable of editing themes may add a Twitter list to a theme's widget area through the WordPress widget editor.

Embed using a Twitter collection URL

Add an embedded collection to a WordPress post by copy-and-pasting a Twitter collection URL on its own line in the post content area. A collection will appear as a stacked list of Tweets.

Photos and videos from national parks in the United States
https://twitter.com/TwitterDev/timelines/539487832448843776
Bears, mountains, sunrise, sunset.

The Twitter plugin for WordPress extends the oEmbed functionality for Twitter collection URLs available since WordPress 4.5 with additional plugin-specific functionality. URL-based embeds pass through the plugin's shortcode handler for site-wide customization of parameters. JavaScript normally returned in an oEmbed response is enqueued through the WordPress resource manager, improving site performance while centralizing customizations.

Embed using a shortcode (default template)

The Twitter plugin for WordPress registers the twitter_collection shortcode handler to allow customization of an embedded collection through a shortcode macro.

Photos and videos from national parks in the United States
[twitter_collection id="539487832448843776" height="400"]
Bears, mountains, sunrise, sunset.

Supported shortcode parameters

AttributeDescriptionExample
idThe unique numeric identifier of the collection. Appears as the final path component of URL539487832448843776
templateDisplay a collection in a responsive grid formatgrid
widthSet the maximum width of the collection in whole pixels500
heightSet a fixed height of the collection in whole pixels400
limitDisplay a static collection expanded to up to N Tweets. The height attribute has no effect when a limit is specified5
chromeToggle the display of design elements in the widget with comma-separated tokens. Accepted tokens: noheader, nofooter, noborders, noscrollbar, transparentnoheader,nofooter
aria_politeSet the ARIA politeness of the collection live region as new Tweets are addedassertive
themeSet a light or dark widget background Overrides the site-wide value set through the plugin settings pagedark
link_colorAdjust the hexadecimal color of links, including hashtags and @mentions, inside each Tweet. Overrides the site-wide value set through the plugin settings page21759b
border_colorAdjust the hexadecimal color of borders between Tweets. Overrides the site-wide value set through the plugin settings paged54e21

Embed using a shortcode (grid template)

The Twitter plugin for WordPress also registers the twitter_grid shortcode handler to display a collection data in responsive grid template. The twitter_grid shortcode handler is also invoked for [twitter_collection template="grid"].

Photos and videos from national parks in the United States
[twitter_grid id="539487832448843776" limit="3"]
Bears, mountains, sunrise, sunset.

Supported shortcode parameters

AttributeDescriptionExample
idThe unique numeric identifier of the collection. Appears as the final path component of URL539487832448843776
widthSet the maximum width of the grid in whole pixels500
limitLimit the maximum number of Tweets displayed5
chromeRemove the footer component of the embedded grid templatenofooter

Site-wide customization using a filter

A website may set site-wide preferences for a collection by acting on the associative array passed to the shortcode_atts_twitter_collectionWordPress filter. Functions acting on the filter should set a decimal integer when modifying the value of the width, height, or limit key.

Example:

/** * Always display a collection at a height of 400 pixels * * @param array $out Parsed user-defined valid attributes or default attribute value * @param array $pairs supported attributes and their default values * @param array $attributes user-defined attributes in the shortcode tag * * @return array options array with our customization applied */functiontimeline_custom_options( $out, $pairs, $attributes )
{
$out['height'] = 400;
return$out;
}
add_filter( 'shortcode_atts_twitter_collection', 'timeline_custom_options', 10, 3 );

A website may also act on the shortcode_atts_twitter_grid shortcode.

Clone this wiki locally