Embedded Tweet
The Twitter plugin for WordPress supports embedding a Tweet by pasting 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 copy-and-pasting a Tweet URL on its own line in the post content area.
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 handler 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
The numerical ID of the desired Tweet.
Example Value: 552230355781320704
Set to false
, 0
, no
, or off
to disable auto-expanding a video, photo, or link preview.
Example Value: false
Set 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.
Example Value: false
Set to left
, center
, or right
to float the Tweet relative to the parent element.
Example Value: right
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_tweet
WordPress filter. Functions acting on the filter should set boolean literals when modifying value for the cards
or conversation
key.
Example:
/** * Always hide previous Tweet in conversation * * @param array $options parsed options with defaults applied * @param array $defaults default values of an embedded Tweet * @param array $attributes user-defined shortcode attributes * * @return array options array with our customization applied */ function tweet_custom_options( $options, $defaults, $attributes ) { $options['conversation'] = false; return $options; } add_filter( 'shortcode_atts_tweet', 'tweet_custom_options', 10, 3 );