Hi,
I’ve recently learnt about a way to add a schema markup template using hubl tokens in the <head> of a blog so that every single blog post has its article/blog schema auto-generated when published (check that out if you need it).
That’s great and I’m trying to do the same and generate a schema markup template using hubl tokens with my blog posts’ breadcrumbs too.
I got something to work however i’m stuck when trying to generate the breadcrumbs schema for a blog post that has several paths:
See this post for instance , it goes like this:
- Home > Blog > Spain > Article
- Home > Blog > Brazil > Article
- Home > Blog > Germany > Article
- Home > Blog > Italy > Article
I want to be able to recreate those 4 paths in my breadcrumbs schema markup template - Here’s the code I have so far:
-----------------------------------
<script type=“application/ld+json”>
{% set regionList = [“teach-english-in-europe”, “teach-english-in-asia”, “teach-english-in-latin-america”, “teach-english-in-middle-east”, “teach-english-in-middle-east”] %}
{% set countryList = [ “teach-english-in-austria”, “teach-english-in-belgium”, “teach-english-in-czech-republic”, “teach-english-in-croatia”, “teach-english-in-france”, “teach-english-in-georgia”, “teach-english-in-germany”, “teach-english-in-hungary”, “teach-english-in-italy”, “teach-english-in-netherlands”, “teach-english-in-poland”, “teach-english-in-portugal”, “teach-english-in-romania”, “teach-english-in-russia”, “teach-english-in-spain”, “teach-english-in-turkey”, “teach-english-in-cambodia”, “teach-english-in-china”, “teach-english-in-hong-kong”, “teach-english-in-india”, “teach-english-in-indonesia”, “teach-english-in-japan”, “teach-english-in-malaysia”, “teach-english-in-myanmar”, “teach-english-in-singapore”, “teach-english-in-south-korea”, “teach-english-in-taiwan”, “teach-english-in-thailand”, “teach-english-in-vietnam”, “teach-english-in-argentina”, “teach-english-in-bolivia”, “teach-english-in-brazil”, “teach-english-in-chile”, “teach-english-in-colombia”, “teach-english-in-costa-rica”, “teach-english-in-dominican-republic”, “teach-english-in-ecuador”, “teach-english-in-mexico”, “teach-english-in-peru”, “teach-english-in-uruguay”, “teach-english-in-bahrain”, “teach-english-in-egypt”, “teach-english-in-iraq”, “teach-english-in-israel”, “teach-english-in-jordan”, “teach-english-in-kuwait”, “teach-english-in-lebanon”, “teach-english-in-morocco”, “teach-english-in-oman”, “teach-english-in-palestine”, “teach-english-in-saudi-arabia”, “teach-english-in-tunisia”, “teach-english-in-turkey”, “teach-english-in-united-arab-emirates” ] %}
{% set regionItem = [] %}
{% set countryItem = [] %}
{% for topic in content.topic_list %}
{% if regionList is containing topic.slug %}
{% set region_new = regionItem.append({“slug”: topic.slug, “name”: topic.name}) %}
{% endif %}
{% if countryList is containing topic.slug %}
{% set country_new = countryItem.append({“slug”: topic.slug, “name”: topic.name}) %}
{% endif %}
{% endfor %}
[{
“@context”: “https://schema.org”,
“@type”: “BreadcrumbList”,
“itemListElement”:
[
{
“@type”: “ListItem”,
“position”: 1,
“name”: “Home”,
“item”: “https://www.internationalteflacademy.com/”
}, {
“@type”: “ListItem”,
“position”: 2,
“name”: “Blog”,
“item”: “{{ group.absolute_url }}”
},{% if regionItem != “[]” and countryItem != “[]” %} {
“@type”: “ListItem”,
“position”: 3,
“name”: “{% for item in regionItem %}{% if loop.first %}{{ item.name|replace(‘Teach English in’,‘’) }}{% endif %}{% endfor %}”,
“item”: “{% for item in regionItem %}{% if loop.first %}{{ blog_tag_url(group.id, item.slug) }}{% endif %}{% endfor %}”
}, {
“@type”: “ListItem”,
“position”: 4,
“name”: “{% for item in countryItem %}{% if loop.first %}{{ item.name|replace(‘Teach English in’,‘’) }}{% endif %}{% endfor %}”,
“item”: “{% for item in countryItem %}{% if loop.first %}{{ blog_tag_url(group.id, item.slug) }}{% endif %}{% endfor %}”
}, {
“@type”: “ListItem”,
“position”: 5,
“name”: “{{ content.name|striptags }}”
}
{% elif regionItem != “[]” and countryItem != “false” %} {
“@type”: “ListItem”,
“position”: 3,
“name”: “{% for item in regionItem %}{% if loop.first %}{{ item.name|replace(‘Teach English in’,‘’) }}{% endif %}{% endfor %}”,
“item”: “{% for item in regionItem %}{% if loop.first %}{{ blog_tag_url(group.id, item.slug) }}{% endif %}{% endfor %}”
},{
“@type”: “ListItem”,
“position”: 4,
“name”: “{{ content.name|striptags }}”
}
{% elif regionItem != “false” and countryItem != “[]”%} {
“@type”: “ListItem”,
“position”: 3,
“name”: “{% for item in countryItem %}{% if loop.first %}{{ item.name|replace(‘Teach English in’,‘’) }}{% endif %}{% endfor %}”,
“item”: “{% for item in countryItem %}{% if loop.first %}{{ blog_tag_url(group.id, item.slug) }}{% endif %}{% endfor %}”
}, {
“@type”: “ListItem”,
“position”: 4,
“name”: “{{ content.name|striptags }}”
}
{%else%} {
“@type”: “ListItem”,
“position”: 3,
“name”: “{{ content.name|striptags }}”
}
{% endif %}]}
{% for item in regionItem %}{% if not loop.last %},{
“@context”: “https://schema.org”,
“@type”: “BreadcrumbList”,
“itemListElement”:
[{
“@type”: “ListItem”,
“position”: 1,
“name”: “Home”,
“item”: “https://www.internationalteflacademy.com/”
}, {
“@type”: “ListItem”,
“position”: 2,
“name”: “Blog”,
“item”: “{{ group.absolute_url }}”
},{% if regionItem != “[]” and countryItem != “[]” %} {
“@type”: “ListItem”,
“position”: 3,
“name”: “{% for item in regionItem %}{% if not loop.last %}{{ item.name|replace(‘Teach English in’,‘’) }}{% endif %}{% endfor %}”,
“item”: “{% for item in regionItem %}{% if not loop.last %}{{ blog_tag_url(group.id, item.slug) }}{% endif %}{% endfor %}”
}, {
“@type”: “ListItem”,
“position”: 4,
“name”: “{% for item in countryItem %}{% if not loop.last %}{{ item.name|replace(‘Teach English in’,‘’) }}{% endif %}{% endfor %}”,
“item”: “{% for item in countryItem %}{% if not loop.last %}{{ blog_tag_url(group.id, item.slug) }}{% endif %}{% endfor %}”
}, {
“@type”: “ListItem”,
“position”: 5,
“name”: “{{ content.name|striptags }}”
}
{% elif regionItem != “[]” and countryItem != “false” %} {
“@type”: “ListItem”,
“position”: 3,
“name”: “{% for item in regionItem %}{% if not loop.last %}{{ item.name|replace(‘Teach English in’,‘’) }}{% endif %}{% endfor %}”,
“item”: “{% for item in regionItem %}{% if not loop.last %}{{ blog_tag_url(group.id, item.slug) }}{% endif %}{% endfor %}”
},{
“@type”: “ListItem”,
“position”: 4,
“name”: “{{ content.name|striptags }}”
}
{% elif regionItem != “false” and countryItem != “[]”%} {
“@type”: “ListItem”,
“position”: 3,
“name”: “{% for item in countryItem %}{% if not loop.last %}{{ item.name|replace(‘Teach English in’,‘’) }}{% endif %}{% endfor %}”,
“item”: “{% for item in countryItem %}{% if not loop.last %}{{ blog_tag_url(group.id, item.slug) }}{% endif %}{% endfor %}”
}, {
“@type”: “ListItem”,
“position”: 4,
“name”: “{{ content.name|striptags }}”
}
{%else%} {
“@type”: “ListItem”,
“position”: 3,
“name”: “{{ content.name|striptags }}”
}
{% endif %}]}{% endif %}{% endfor %}
{% for item in countryItem %}{% if not loop.last %},{
“@context”: “https://schema.org”,
“@type”: “BreadcrumbList”,
“itemListElement”:
[{
“@type”: “ListItem”,
“position”: 1,
“name”: “Home”,
“item”: “https://www.internationalteflacademy.com/”
}, {
“@type”: “ListItem”,
“position”: 2,
“name”: “Blog”,
“item”: “{{ group.absolute_url }}”
},{% if regionItem != “[]” and countryItem != “[]” %} {
“@type”: “ListItem”,
“position”: 3,
“name”: “{% for item in regionItem %}{% if not loop.last %}{{ item.name|replace(‘Teach English in’,‘’) }}{% endif %}{% endfor %}”,
“item”: “{% for item in regionItem %}{% if not loop.last %}{{ blog_tag_url(group.id, item.slug) }}{% endif %}{% endfor %}”
}, {
“@type”: “ListItem”,
“position”: 4,
“name”: “{% for item in countryItem %}{% if not loop.last %}{{ item.name|replace(‘Teach English in’,‘’) }}{% endif %}{% endfor %}”,
“item”: “{% for item in countryItem %}{% if not loop.last %}{{ blog_tag_url(group.id, item.slug) }}{% endif %}{% endfor %}”
}, {
“@type”: “ListItem”,
“position”: 5,
“name”: “{{ content.name|striptags }}”
}
{% elif regionItem != “[]” and countryItem != “false” %} {
“@type”: “ListItem”,
“position”: 3,
“name”: “{% for item in regionItem %}{% if not loop.last %}{{ item.name|replace(‘Teach English in’,‘’) }}{% endif %}{% endfor %}”,
“item”: “{% for item in regionItem %}{% if not loop.last %}{{ blog_tag_url(group.id, item.slug) }}{% endif %}{% endfor %}”
},{
“@type”: “ListItem”,
“position”: 4,
“name”: “{{ content.name|striptags }}”
}
{% elif regionItem != “false” and countryItem != “[]”%} {
“@type”: “ListItem”,
“position”: 3,
“name”: “{% for item in countryItem %}{% if not loop.last %}{{ item.name|replace(‘Teach English in’,‘’) }}{% endif %}{% endfor %}”,
“item”: “{% for item in countryItem %}{% if not loop.last %}{{ blog_tag_url(group.id, item.slug) }}{% endif %}{% endfor %}”
}, {
“@type”: “ListItem”,
“position”: 4,
“name”: “{{ content.name|striptags }}”
}
{%else%} {
“@type”: “ListItem”,
“position”: 3,
“name”: “{{ content.name|striptags }}”
}
{% endif %}]}
{% endif %}{% endfor %}
]
</script>
-----------------------------------
With this code, I do generate 4 breacrumb items like i want to for this post example.
However - instead of pulling the spain item once, the brazil item once, the germany item once, and the italy item once - it pulls all of them together in the same iteration 4 times.
See this screenshot:
Obviously - I’m not trying to get someone to write the code for me for free, i’m just wondering if someone can put me in the right direction so i can pull one item at a time in that breadcrumb schema markup?
Thank you so much for your help!
