Thursday, September 1, 2011

Better description for Google+ links

When adding a link on Google+ (My Google+ profile) I found that the description was not from the actual blog post but from some text I have in a column to the left of my blog. At least it is possible to remove the description within Google+.

It’s right now not possible when the +1 button is used, hopefully it will be eventually.

As I have a Google Blogger Blogspot blog I tried to find a better solution for this.

On the API page for the +1 button I found a bit of information using Schema.org microdata, Open Graph protocol or Meta "title" and "description" tags.

I edited the blog template after taking a backup of it.

<body itemscope itemtype='http://schema.org/Blog'>

I got this error editing the template: Attribute name "itemscope" associated with an element type "body" must be followed by the ' = ' character.

So I changed it to:
<body itemscope='' itemtype='http://schema.org/Blog'>

<h3 class='post-title' itemprop='name'>

<p itemprop='description'><data:post.body/></p>

Adding itemprop='description' to <p> did not work so I instead added it to

<div class='post-body' itemprop='description'>

What finally worked for me was:

<body itemscope='' itemtype='http://schema.org/Blog'>

<h3 class='post-title' itemprop='name'>

<div class='post-body' itemprop='description'>

Now trying to share a link the description is taken from the blog post instead.

Note that above it says “Project Sparkis” instead of “Project Spark is”.

I found that another trick improved it (Warning! See update at the bottom). Here is how to make the meta description dynamic taking the content from the post body.

Edit the HTML Template and look for <data:post.body/>

Right above the tag, add:

      <b:if cond='data:blog.pageType == &quot;item&quot;'>
         <meta expr:content='data:post.body' name='description'/>
      </b:if>

      <p><data:post.body/></p>

And look the link is even retained now.

Now if there is a lot of text the meta description will be quite large but from what I understand Google and other search engines just takes the first 250 or so characters anyway. If you use snippets on the blog this might be a way:
<meta expr:content='data:post.snippet' name='description'/>

But if you know of a way to trim 'data:post.body' let me know.

Update: I found that the description using 'data:post.body' for this blog post did not work. Probably because of the code snippets used in the post. It also messed up the actual blog post as seen on the blog so I had to remove that.

No comments:

Post a Comment