HTML5 Snippets - Customize Your Twitter Cards

HTML5 Snippets - Customize Your Twitter Cards "View On Web" Text Link Using The <meta> Element

Published:

Rate Article (Sign in and be the first to rate this article.)

Article Details

Views: 1093

First Published:

Word Count: 903

Edition: 1

Now when you expand a tweet that is using one of the Twitter Cards, you will see a text link that states "View on web" at the footer of the card or in-other words at the bottom of the tweet. Twitter will allow you to change part of the text for the "View on web" text link to your domain name, more specifically Twitter will allow you to replace the word "web" in the text link with your domain name. In-order to customize the "View on web" text link you will need to add one more additional <meta> element to your Twitter Card.

Now in-order to change the word "web" in the text link for your Twitter Card you will need the <meta> element along with the name attribute and content attribute. You will then need to include the twitter:domain value for the name attribute in-order to tell Twitter's web crawler to expect some text from your web page to replace the word "web" from the "View on web" text link for your Twitter Card. Next you will need to include the content attribute. The content attributes value should be the name of your domain, for instance, ("example.com") or ("http://www.example.com"), are acceptable values for the content attribute. A tip that you should remember is that Twitter will actually allow you to state a value other than your domain name for the content attributes value.

On a side note your Twitter Cards "View on web" text link actually links to your web page that was tweeted. The URL value for the "View on web" text link is automatically grabbed from the content attributes value associated with the twitter:url value for the name attribute, which is located in another <meta> element for your Twitter Card.

It's important to remember that in-order for your Twitter Cards <meta> elements to work you must first apply for the Twitter Card of your choice, which is free. The process usually consists of you signing in to your Twitter account and then entering the URL of a web page from your web site containing the Twitter Cards <meta> elements into the Validate & Apply text box. Once your web page has been validated, you can then request for the final approval for your Twitter Card. When requesting for the final approval for your Twitter Card you will have to provide some basic information about your web site and Twitter account. You then can expect a response within a few weeks or less, but you will usually hear a response within minutes by email when your request has been reviewed. Once approved you will then need to wait for Twitter's web crawler to re-index your web pages meta information in-order to see your Twitter Card in action, which should be about a week or so. Another important thing to remember is that if you want to use other kinds of Twitter Cards you will need to start the process over again of validating and requesting final approval for your Twitter Card each time. You can learn more about Twitter Cards at Twitter's developers web page for Twitter Cards.

Now let me first show you the code by itself for the HTML snippet for customizing your Twitter Cards "View on web" text link using the <meta> element. And then I will show you how to code and where to place the HTML snippet for both HTML5 and XHTML5.

Here is the HTML code snippet below to customize your Twitter Cards "View on web" text link using the <meta> element.


<meta name="twitter:domain" content="Your domain name or some other type of information preferably about your web site" />

Here is the HTML code snippet to customize your Twitter Cards "View on web" text link using the <meta> element for HTML5 in the example below.


<!DOCTYPE html>
<html>
<head>
 <meta charset="UTF-8">
 <title>Welcome To HTML5</title>
 <meta name="twitter:card" content="photo">  
 <meta name="twitter:image" content="http://www.example.com/some-image.jpg">  
 <meta name="twitter:url" content="http://www.example.com/twitter-photo-card.htm">  
 <meta name="twitter:domain" content="Example.com">  
</head>
<body>
  
 <p>Your Twitter Cards "View on web" text link should now read "View on Example.com".</p>  

</body>
</html>

And here is the HTML code snippet to customize your Twitter Cards "View on web" text link using the <meta> element for XHTML5 in the example below.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">  
<head>
 <meta charset="UTF-8" />
 <title>Welcome To XHTML5</title>
 <meta name="twitter:card" content="photo" />  
 <meta name="twitter:image" content="http://www.example.com/some-image.jpg" />  
 <meta name="twitter:url" content="http://www.example.com/twitter-photo-card.htm" />  
 <meta name="twitter:domain" content="Example.com" />  
</head>
<body>

 <p>Your Twitter Cards "View on web" text link should now read "View on Example.com".</p>  

</body>
</html>

Article Tags

Tag Article (Sign in if you want to tag this article.)

Share This Article

Send To Facebook Link

Tweet This Link

Send To LinkedIn Link

Send To StumbleUpon Link

Digg This Link

Send To Google Plus One Share Link

Send To Reddit Link

Send To Tumblr Link

Send To Delicious Link

Send To FriendFeed Link

Send To Diigo Link

Email Link

AddThis Link

0 Comments

Leave Comment (Sign in and be the first to comment on this article.)

Important

This site cannot guarantee the accuracy of articles, comments, answers and other types of content or media submitted by members or anonymous users and guests, and we recommend that you use common sense when following any advice or information found on this site. Read our full Content Disclaimer Agreement for further information.