How to Add Twitter Cards to WordPress Site (Guide To Know)

0

How to Add Twitter Cards to the WordPress Site

Do you want to add Twitter cards to your WordPress site? Twitter cards allow you to connect rich media to tweets that link to your content. This can be terribly similar to sharing a link on Facebook that automatically displays a preview with title, summary and thumbnail of the page content. During this article, we will show you how to add twitter cards to the WordPress site.

How do Twitter cards work?

How to Add Twitter Cards to the WordPress Site

How to Add Twitter Cards to the WordPress Site

When your tweet has a link to a website that has twitter enabled cards, there is an option to see the summary. Every time another user clicks on the tweet, they will see this summary as well as the screenshot below. You will see the example live by visiting our Twitter page.

The biggest advantage of getting twitter cards is that you will increase the number of people who follow your Twitter accounts through attribution content. Usually people tweet their links without giving you the correct attribution.

We have noticed this specifically from some popular content curators. We tweet our articles with none via @ Youtubetvnews or RT @ Youtubetvnews. This may be your right, however we / you as publishers will miss especially when others retweet your content with the attributes of another person.

Often, content curators do that to keep tweets short and to secure retweets from their own tweets. With Twitter cards, this problem is solved because you get credit to your website from every tweet mentioning your article. Note: we are not choosing on content curators. This can be a default of 140 characters, and twitter is helping to fix it with the Twitter cards.

Now that you know the benefits of Twitter cards, let’s take a look at how to implement on the WordPress site.

How to add Twitter cards in WordPress

There are two ways to add Twitter cards in WordPress. Let’s look at both.

Method 1: Add the code yourself

This method needs to add code to theme or theme themed files. Simply open the header.php file and add this code just before the </ head> tag.

<?php
#twitter cards hack
if(is_single() || is_page()) {
$twitter_url = get_permalink();
$twitter_title = get_the_title();
$twitter_desc = get_the_excerpt();
$twitter_thumbs = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), full );
$twitter_thumb = $twitter_thumbs[0];
if(!$twitter_thumb) {
$twitter_thumb = ‘http://www.gravatar.com/avatar/8eb9ee80d39f13cbbad56da88ef3a6ee?rating=PG&size=75’;
}
$twitter_name = str_replace(‘@’, ”, get_the_author_meta(‘twitter’));
?>
<meta name=”twitter:card” value=”summary” />
<meta name=”twitter:url” value=”<?php echo $twitter_url; ?>” />
<meta name=”twitter:title” value=”<?php echo $twitter_title; ?>” />
<meta name=”twitter:description” value=”<?php echo $twitter_desc; ?>” />
<meta name=”twitter:image” value=”<?php echo $twitter_thumb; ?>” />
<meta name=”twitter:site” value=”@lifenan99″ />
<?
if($twitter_name) {
?>
<meta name=”twitter:creator” value=”@<?php echo $twitter_name; ?>” />
<?
}
}
?>

If you do not know how to work with PHP or run into problems with method 1, use Method 2.

Method 2: Yoast SEO plugin

If you are using WordPress SEO by Yoast plugin, then you are out of luck. Yoast has integrated the integration of twitter cards, so activation can be a matter of few clicks.

Just go to the “Social” page of the Yoast SEO Settings page. Enter your Twitter username and save your changes.

After that click on the Twitter tab. Under the Twitter tab you need to check the box to Add metadata to the Twitter card. Select a default card type to choose from. You can choose to show summary or summary with large image.

How to Add Twitter Cards to the WordPress Site

How to Add Twitter Cards to the WordPress Site

The next factor you want to do is go to the Users page »My profile. You’ll see a new field in Contact Information for your twitter username. Enter your twitter username there.

If you are running a website with multiple authors, advise their authors to complete this part in their profile. In this way each specific author gets credit for his work in a similar way.

That’s all that has successfully added the meta tags of the Twitter cards to your WordPress site. This method is by far the easiest method. Since we use WordPress SEO by Yoast on all our websites, we are using this method.

Test and validate the Twitter card

Before the links on your WordPress website begin to show Twitter cards, you first want to check it on the validator of the Twitter card.

Just go to the Validator page of the card on the Twitter Developers website. Enter the URL of any posting on your WordPress website and click the preview button.

Twitter will show you a preview of your Twitter card. Twitter has implemented a system that automatically lists white domains when tested with the validator or simply share a URL on Twitter. We hope this article will help you add Twitter cards in WordPress.

LEAVE A REPLY

Please enter your comment!
Please enter your name here