How to add Twitter Cards in WordPress

 In Code, PHP

Twitter Cards in WordPress
With Twitter Cards, you can attach photos, videos and media to Tweets that drive traffic to your website. The reader sees more information than a standard Tweet, and clicking on the image takes the user to your website.

Simply add a few lines of HTML to your webpage to enable Twitter Cards in WordPress, and users who Tweet links to your content will have a “Card” added to the Tweet that’s visible to all of their followers.

Drive engagement from your Tweets

The below Card types have a beautiful consumption experience built for Twitter’s web and mobile clients:

  • Summary Card: Default Card, including a title, description, thumbnail, and Twitter account attribution.
  • Summary Card with Large Image: Similar to a Summary Card, but with a prominently featured image.
  • Photo Card: A Card with a photo only.
  • Gallery Card: A Card highlighting a collection of four photos.
  • App Card: A Card to detail a mobile app with direct download.
  • Player Card: A Card to provide video/audio/media.
  • Product Card: A Card optimized for product information.

To learn more about how Card meta tags and Twitter web crawler works, check out Getting Started Guide.

Twitter Cards in WordPress

Paste the following code before the closing of the tag in your header.php file.

ID), full );
  $twitter_thumb  = $twitter_thumbs[0];
    if(!$twitter_thumb) {
    $twitter_thumb = '';
  $twitter_name = str_replace('@', '', get_the_author_meta('twitter'));


Allow Twitter access via the robots.txt file.

User-agent: Twitterbot

Recent Posts
Contact Us

Send us an email and we'll get back to you, asap.

Not readable? Change text. captcha txt

Start typing and press Enter to search