Skip to main content

Setting up Twitter Cards in Blogger

There are plenty of blog posts explaining how to add Twitter Card integration to your Blogger posts but I haven't seen any that are written for the newer Blogger UI. The code that does the integration hasn't changed since this article in 2013, but the steps to add it to your theme have. 

If you haven't logged onto Blogger, do so. You should see this panel on your left.




Pick "Theme" and you will see something that looks like this on the top portion of your screen.



First things first, make a backup. Click on the little arrow

If you are using the classic themes, it will look like this. 

After clicking on the arrow, pick Backup. Download the file. It's the same for classic themes.





Pick download. Save the file somewhere just in case you need to recover your theme. While editing your theme will not destroy any of your pages or posts, it can cause problems for the theme you are using if you make a mistake. If you've spent some time editing your blogroll and customizing your colors and fonts, you don't want to lose this so make sure you make a backup.

Now that you have a backup, pick Edit HTML. 




If you are using the classic theme, click on EDIT HTML button rather than activate the context menu from the drop down.  

You should see some scary looking HTML code in a code editor. Click anywhere in the code editor. Once you do that, you need to activate search. If you are using a Mac, pick command-F to search. On windows it should be control-F. 

If you see this search box, you did it correctly. 




If you see the browser search box, you didn't click in the code editor. Close the browser's search pop up and then click in the code editor and try the search command again. 

Search for </head> by typing that and then hitting enter. This will search for the bottom of the head element. 



If you see something like this, you are in the right spot. You should see the </head> tag, which marks the end of the page's head portion and the start of the body of the web page. 




Now you need to copy over the text . Copy it from the block below. 


<!--  START - TWITTER CARD TAGS   -->
<meta name="twitter:card" content="summary"/> 
<meta name="twitter:site" content="@YOUR-TWITTER-ACCOUNT-NAME"/> <meta name="twitter:domain" content="YOUR-BLOG-URL"/>

<b:if cond='data:blog.pageType == &quot;item&quot;'><meta name="twitter:title" expr:content='data:blog.pageName'/><b:else/>
<meta expr:content='data:blog.homepageUrl' name='twitter:url'/>
<meta expr:content='data:blog.pageTitle' name='twitter:title'/></b:if>
<b:if cond='data:blog.postImageThumbnailUrl'><meta name="twitter:image:src" expr:content='data:blog.postImageThumbnailUrl'/><b:else/><meta name="twitter:image:src" content='URL-FOR-IMAGE-YOU-WANT-TO-USE-IF-THERE-IS-NOT-A-THUMBNAIL-PHOTO-IN-THE-POST' /></b:if> 
<b:if cond='data:blog.metaDescription'><meta name="twitter:description" expr:content='data:blog.metaDescription'/><b:else/><!-- Still looking for a way to use the post snippet if there's no description --></b:if>

<meta name='twitter:url' expr:content='data:blog.canonicalUrl'/>
<!--  END - TWITTER CARD TAGS   -->

Following the instructions from this article in 2013 you need to edit the following.

YOUR-BLOG-URL

This the full URL for the blog. 

URL-FOR-IMAGE-YOU-WANT-TO-USE-IF-THERE-IS-NOT-A-THUMBNAIL-PHOTO-IN-THE-POST

This is an image to use when there is no image in the article. You can pick an image previously uploaded to your blog or your Twitter profile image. I removed that block for this blog by deleting this entire section:

<b:if cond='data:blog.postImageThumbnailUrl'><meta name="twitter:image:src" expr:content='data:blog.postImageThumbnailUrl'/><b:else/><meta name="twitter:image:src" content='URL-FOR-IMAGE-YOU-WANT-TO-USE-IF-THERE-IS-NOT-A-THUMBNAIL-PHOTO-IN-THE-POST' /></b:if> 

And lastly, the optionally YOUR-TWITTER-ACCOUNT-NAME

You can remove that line if you do not want to use it. 

This is what it looks like on this blog. 


The text needs to be inserted before the </head> tag as the code will only work properly in the page header and not in the page body.


When you are done making those edits, click on the floppy icon to save. It is on the top right corner.





Then click on the arrow in the top left to go back to the dashboard screen. 


You can now test this by tweeting a URL from your blog. If its is working you should see a tweet card with an image from your post, title and blog URL.









Comments

Popular posts from this blog

Capturing text from any Mac Application into Emacs org-mode with Automator and org-protocol

After decades of using vi and Vim I switched to  Spacemacs  which is an amazing vi keystroke emulation layer running on Emacs and configured with an amazing set of preconfigured layers for different tasks. I decided to give it a try after seeing Org-Mode in action and seeing it was a nice taking system with integrations with almost anything imaginable. A few weeks ago I found out about org-protocol and followed this post  by Jethro on using a bookmarket to capture from the Web to Emacs.  This page assumes a few things You use Emacs on a Mac You are using org and understand how to use capture and capture templates. You need to yank text from random apps into Emacs You don't need to be using Spacemacs and this should work with any install of Emacs that supports org, org-capture and org-protocol. Creating Automator Action Start Automator. It's this icon. I'm guessing many people have had this for years and have never used it.  Open it and pick Quick Action Grab the...

Halloween Candy Distribution Robot Chute

I am not a hardware guy and my Brooklyn apartment lacks true workshop space but we were able to put together a reasonably well done candy chute robot able to deliver candy directly into Trick-or-Treat's candy bags.  My wife wanted the robot to blink lights and wave an arm. I decided to use a servo motor driven by a Raspberry pi pico running MicroPython. The pico and MicroPython were chosen because I had them already from prior projects with my son.  Legos, chopsticks and leftover screws. Only the best. Cardboard, aluminum foil and Tupperware to protect the electronics. Those are the bags of candy and we managed to go through all of the candy by dark. This is what it looked like up on our balcony. How do you get the candy down to the trick-or-treaters? A dryer duct. Last time we used plastic sheeting and zip ties. The $25 to get a duct was worth it. We tested it with fun sized chocolate, smarties, double bubble gum, skittles and m&ms. The bagged candy, skittles and M...

I can't vote for that, no can do

Mastodon