Below is the HTML actually used to display the breadcrumbs on each page
<c:forEach items="${breadcrumbArray}" var="breadcrumb" varStatus="loopCounter">
<c:if test="${breadcrumb ne 'store'}">
<li class="breadcrumb__item">
<c:choose>
<c:when test="${not loopCounter.last}">
<a href="/${breadcrumb}">${breadcrumb}</a>
</c:when>
<c:otherwise>
${fn:replace(breadcrumb, '-', ' ')}
</c:otherwise>
</c:choose>
</li>
</c:if>
</c:forEach>
Javascript used to generate the schema dynamically
<script type="text/javascript">
$(document).ready(function(){
var el = document.createElement('script');
el.type = 'application/ld+json';
el.text = JSON.stringify({ "@context": "https://schema.org/",
"@type": "BreadcrumbList",
"itemListElement": [{
"@type": "ListItem",
"position": 1,
"name": "",
"item": ""
}]
});
document.querySelector('head').appendChild(el);
});
</script>
The schema for example for " Home > Our Mission > Who We Are " should be generated like:
<script type="application/ld+json">
{
"@context": "https://schema.org/",
"@type": "BreadcrumbList",
"itemListElement": [{
"@type": "ListItem",
"position": 1,
"name": "Home",
"item": "https://corp.com/"
},{
"@type": "ListItem",
"position": 2,
"name": "Our Mission",
"item": "https://corp.com/our-mission/"
},{
"@type": "ListItem",
"position": 3,
"name": "Who We Are",
"item": "https://corp.com/our-mission/who-we-are"
}]
}
</script>
The script is not getting appended to the 'head' tag ..