我想看看是否有人可以发布一个示例,说明如何动态创建 JSON-LD 以使用 JQuery 创建 Google Rich Card?如果有人可以向我展示如何实现这一点的示例,我将非常感激。
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [{
"@type": "ListItem",
"position": 1,
"item": {
"@id": "https://www.avenue.com/",
"name": "Home",
}
},{
"@type": "ListItem",
"position": 2,
"item": {
"@id": "https://www.avenue.com/en_US/plus-size-clothing/dresses/",
"name": "Plus Size Dresses",
}
}]
}
</script>
最佳答案
您不应该使用 jQuery 创建它。您应该将其放入 isml 模板中,遵循以下示例:
<script type="application/ld+json">
<isprint value="${JSON.stringify(ldJSON)}" encoding="off"/>
</script>
或者如果您希望硬编码结构:
<script type="application/ld+json">
{
"@context": "${context}",
"@type": "${type}",
"url": "<isprint value="${varURL}" />",
"potentialAction": {
"@type": "${searchType}",
"target": "<isprint value="${theTarget}" />{search_term_string}",
"query-input": "required name=search_term_string"
}
}
</script>
关于javascript - 添加所需的 Schema.org JSON LD 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50342855/