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

Embedded Tweet

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

The Twitter plugin for WordPress supports embedding a Tweet by pasting a Tweet URL into the WordPress post editor or by customizing a [tweet]WordPress shortcode.

Embed using a Tweet URL

Add an embedded Tweet to a WordPress post by pasting a Tweet URL on its own line in the post editor.

Check out this cool Tweet:
https://twitter.com/Interior/status/552230355781320704
That was a cool Tweet.

The Twitter plugin for WordPress extends the oEmbed Tweet URL functionality available since WordPress 3.4 with additional plugin-specific functionality. URL-based embeds pass through the plugin's shortcode handler for site-wide customization of Tweet 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

The Twitter plugin for WordPress registers the tweet shortcode to allow embedded Tweet customization through a shortcode macro.

Check out this cool Tweet:
[tweet id="552230355781320704" align="right"]
That was a cool Tweet.

Supported shortcode parameters

AttributeDescriptionExample
idThe numerical ID of the desired Tweet.552230355781320704
cardsSet to false, 0, no, or off to disable auto-expanding a video, photo, or link preview.false
conversationSet to false, 0, no, or off to disable display of the previous Tweet in a conversation if the Tweet was in reply to another Tweet.false
alignSet to left, center, or right to float the Tweet relative to the parent element.right
widthSet a maximum width of the Tweet500
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

Site-wide customization using a filter

A website may set site-wide preferences for embedded Tweets by acting on the associative array passed to the shortcode_atts_tweetWordPress filter. Functions acting on the filter should set boolean literals when modifying the value of the cards or conversation key.

Example:

/** * Always hide previous Tweet in conversation * * @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 */functiontweet_custom_options( $out, $pairs, $attributes )
{
$out['conversation'] = false;
return$out;
}
add_filter( 'shortcode_atts_tweet', 'tweet_custom_options', 10, 3 );

Clone this wiki locally