Twitter ad conversion tracking WordPress shortcode

The Twitter plugin for WordPress makes it easy to track Twitter advertising campaign conversions or build a remarketing audience with the twitter_tracking WordPress shortcode. Configure a widget, add the shortcode to a post content area, or evaluate the shortcode using the do_shortcode WordPress function to add Twitter ads tracking to your webpages.

The Twitter plugin for WordPress only includes additional trackers when explicitly specified by your website or its authors. Please read Twitter’s advertising tracker disclosure policies and modify your site’s privacy policy as appropriate before using this feature.

Copy a universal website tag from a code snippet generated on

Screenshot universal website tag code snippet

Supported shortcode parameters

Attribute Description Example
id The Twitter advertising tracking identifier generated by Twitter’s conversion tracking tools. 12b34

Set the tracking ID using a filter

A website may wish to set tracking IDs for specific pages by acting on the associative array passed to the associative array passed to the shortcode_atts_twitter_tracking WordPress filter.

A shortcode parameter with no explicitly provided id attribute will return an empty string unless overridden during the WordPress filter process.


 * Set a tracking ID for specific pages
 * @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
function twitter_tracking_custom_options( $out, $pairs, $attributes )
  if ( is_page( 42 ) ) {
    $out['id'] = '12b34';
  return $out;
add_filter( 'shortcode_atts_twitter_tracking', 'twitter_tracking_custom_options', 10, 3 );