2017-12-20

Breadcrumbs with Structured Data for Blogger

日本語»

A lot of blogs refer to

Breadcrumb for Blogger - Blogger Widgets

And the original idea is based on

Hoctro’s Archived Blog - Trang Lưu Trữ Học Trò: Archived Post: Adding a Breadcrumb Trail to your Blogger Post

Thank you, Hoktro-san, Aneesh-san. It’s still useful but has the following issues at present.

  • The structured data type definition is based on the obsolete Data-Vocabulary.org, not schema.org.
  • Not using ordered list (<ol> <li>), commonly used for breadcrumbs.

I try to modify these issues.

FYI

1. Add <b:includable>

The modified code snippet of <b:includable> is as follows.
It uses RDFa as a structured data format.

<b:includable id='breadcrumb' var='posts'>
<!-- breadcrumb start -->
<ol id='breadcrumb' typeof='BreadcrumbList' vocab='http://schema.org/'>
<b:if cond='data:blog.homepageUrl != data:blog.url'>
  <li property='itemListElement' typeof='ListItem'>
    <a expr:href='data:blog.homepageUrl' property='item' typeof='WebPage'>
    <span property='name'>Home</span></a>
    <meta content='1' property='position'/>
  </li>
  <b:if cond='data:blog.pageType == &quot;static_page&quot;'>
    <li><data:blog.pageName/></li>
  <b:else/>
    <b:if cond='data:blog.pageType == &quot;item&quot;'>
      <!-- breadcrumb for the post page -->
      <b:loop values='data:posts' var='post'>
        <b:if cond='data:post.labels'>
          <b:loop index='index' values='data:post.labels' var='label'>
          <!-- b:if cond='data:label.isLast == &quot;true&quot;' -->
            <li property='itemListElement' typeof='ListItem'>
              <a expr:href='data:label.url' property='item' typeof='WebPage'>
              <span property='name'><data:label.name/></span></a>
              <meta expr:content='data:index + 2' property='position'/>
            </li>
          <!-- /b:if -->
          </b:loop>
          <li><data:post.title/></li>
        <b:else/>
          <li>Unlabelled</li>
        </b:if>
      </b:loop>
    <b:else/>
      <b:if cond='data:blog.pageType == &quot;archive&quot;'>
        <!-- breadcrumb for the label archive page and search pages.. -->
        <li>Archives for <data:blog.pageName/></li>
      <b:else/>
        <b:if cond='data:blog.pageType == &quot;index&quot;'>
          <b:if cond='data:blog.pageName == &quot;&quot;'>
            <li>All posts</li>
          <b:else/>
            <li>Posts filed under <data:blog.pageName/></li>
          </b:if>
        </b:if>
      </b:if>
    </b:if>
  </b:if>
</b:if>
</ol>
<!-- breadcrumb end -->
</b:includable>

Insert this snippet before <b:includable id='main' var='top'> in Edit HTML.

* I recommend the backup before editing.

Note:

After saving it, the formatter of Edit HTML moves the snippet, as snippets are in an alphabetical order of id, and indent the first line of the snippet.

  • If you comment out <b:if cond='data:blog.homepageUrl != data:blog.url'> and end-tag </b:div>, you can display the breadcrumb trail at all times including top page.
  • If you comment in <!-- b:if cond='data:label.isLast == &quot;true&quot;' --> and <!-- /b:if -->, the breadcrumbs include only the last label (in alphabetical order).
    (When you use more than one label, labels are sorted forcibly in alphabetical order.)

Usage of Search Function in Edit HTML

In Edit HTML, press Ctrl + F keys, then search box is displayed in upper right corner.
Input the search string and press Enter key. Each time press Enter key, the cursor jumps to the next match.

2. Add <b:include>

Next, insert the following widget tag for display before the part of <b:include data='top' name='status-message'/>.

<b:include data='posts' name='breadcrumb'/> 
  • If you put it just before </div> corresponding to <div class='blog-posts hfeed'>, the breadcrumb list is placed at the bottom of the page.
  • If you put it before <b:if cond='!data:mobile'>, the breadcrumb list can be shown in mobile pages as well.

3. Add CSS

Finally, add CSS as follows. Please modify as needed.

/* breadcrumb */
ol#breadcrumb{
    font-size:13px;
    padding: 8px;
}
#breadcrumb li {
    display: inline;
    list-style-type: none;
}
#breadcrumb li:after {
    content: " > ";
}
#breadcrumb li:last-child:after {
    content: none;
}

It’s all done.

Structured Data Testing Tool

You can check whether the breadcrumb list is working properly with Google Structured Data Testing Tool.

You must input URLs showing breadcrumbs.

You may find some errors in BlogPosting (not breadCrumbList).
You don’t have to care about it unless you want to reflect these error items correctly to search results. See Structured Data testing Tool errors on Blogpost Blogger - Google Product Forum.

If you want to fix them, this site may help you.

Remaining issue

Breadcrumbs are listed in alphabetical order, not showing the actual hierarchy.
To be continued in Blogger: Sort Breadcrumbs by Label Frequency.

28 comments:

  1. Hi! I am trying to implement this on my blog, but I don´t want that all the labels on the post appear on the breadcrumbs. How can I just put 3 labels on it? Thanks!

    ReplyDelete
    Replies
    1. Hi, Angélica. You can find <!-- b:if cond='data:label.isLast == "true"' --> in 18th line. Please replace it with <b:if cond='data:index &lt; 3'>. And replace <!-- /b:if --> in 24th line with </b:if>. Then 3 labels are displayed at most.(Note they are in alphabetical order.) Thanks.

      Delete
    2. Hi nkuri! I made those changes, but all the labels are still displaying...Thanks!

      Delete
    3. Hi, thanks for trying. I tried it in my own pages and confirmed it worked fine. Let me make sure about "3 labels". Breadcrumbs such as "Home > labelA > labelB > labelC > labelD > PostTitle" have 4 labels. You want to omit "labelD". Is it right?

      Delete
  2. nkuri yes, I want to omit labelD. I misunderstood the way the trail is made, so I change the number like this and it works fine! (Home + 2 labels)
    I just didn't want the breadcrumbs so long because in some post I have 5 labels or so...
    I was trying to paste the code here but could't, haha!
    Thank you very much for your help, very kind from your part!

    ReplyDelete
    Replies
    1. Hello and thanx for the tutorial,it works.I tried adding up a custom CSS to it and it's looking messed up with three ">" coming in between out of nowhere,can you please take a look at this post-->https://thatswhtilike.blogspot.com/2018/06/hellequin-chronicles-series-books-1.html or any. Thank You!

      Delete
  3. Replies
    1. Hi, Ismail. Please use a standard way of adding CSS on blogger, you can search online.

      Delete
  4. great , it's work for me fine , but I got this error at home page
    @type
    BreadcrumbList
    itemListElement
    Veuillez saisir une valeur pour le champ itemListElement

    --- any help thanks Nkuri ---

    ReplyDelete
    Replies
    1. I hope this page will be of some help.
      https://support.bigcommerce.com/s/question/0D54O000065iTY0SAM/alert-a-value-for-the-itemlistelement-field-is-required

      Delete
  5. Please i need video to make this changes

    ReplyDelete
  6. Hi, does this still works in 2020? I'm a real newbie on schema.org.

    ReplyDelete
    Replies
    1. Yes, I use RDFa, which is supported by Gooogle search. FYI: https://developers.google.com/search/docs/guides/intro-structured-data#structured-data-format

      Delete
  7. hello, your code is working fine but it is showing error for homepage.

    please validate your site's homepage schema.

    ReplyDelete
    Replies
    1. Yes, I've found my top page has some errors in breadcrubmList by Google
      testing tool. These errors seem to be irrelevant to breadcrumbList.
      When I pushed VALIDATE button again (after adding a space in the left pain), the errors disappered. I don't think that is good. It may be better off not putting breadcrumbs on top page. Let me think. Thank you for your information.

      Delete
  8. For my main page it is not showing any structured data but for individual pages it is showing. Any idea what is going wrong with my website?

    ReplyDelete
  9. Sorry for the late reply.
    Did you use Google Rich Result Test? https://search.google.com/test/rich-results
    (Structured Data Testing Tool is obsolete.)
    And can't you find any "Breadcrumbs" in the test result?

    Could you confirm "" and "" were commented out, as the notes of this post?

    ReplyDelete
  10. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work palottery

    ReplyDelete
  11. Thanks for the information, very useful!

    ReplyDelete

  12. Hi, I don't know why but with all the tutorials I've tried (including yours) the "breadcrumbs" always appear in the column like a numbered list. I do not understand why..

    ReplyDelete
  13. Hi, thank you for your comment.
    I think you are saying why we need to use the <ol> <li> elements.
    The main reason is to display the breadcrumb list in the search results on Google.
    Please see:
    https://developers.google.com/search/docs/appearance/structured-data/breadcrumb
    If you don't need it, you don't have to use numbered list.

    ReplyDelete
    Replies

    1. Thanks for the reply. I actually meant that, graphically, the Breadcrums appear one below the other in a numbered bullet list and not in a single horizontal line, as it should be.

      Delete
    2. Yes, without CSS "display: inline", the breadcrumbs would be displayed vertically. It's a bit a hassle, but it is necessary to modify CSS.

      Delete