问题原文
原帖链接 · Mack Shaw · CC BY-SA 4.0
I am wondering where should i put the schema markup code? Should i put it in the <head> tag or in the <body> tag?
This is a sample code from Google and they haved added it in the tag but I read somewhere that it is completely fine to put it either <head> or <body> tag.
https://developers.google.com/search/docs/appearance/structured-data/review-snippet
<script type="application/ld+json">
{
"@context": "https://schema.org/",
"@type": "Review",
"itemReviewed": {
"@type": "Restaurant",
"image": "https://www.example.com/seafood-restaurant.jpg",
"name": "Legal Seafood",
"servesCuisine": "Seafood",
"priceRange": "$$$",
"telephone": "1234567",
"address" :{
"@type": "PostalAddress",
"streetAddress": "123 William St",
"addressLocality": "New York",
"addressRegion": "NY",
"postalCode": "10038",
"addressCountry": "US"
}
},
"reviewRating": {
"@type": "Rating",
"ratingValue": "4"
},
"name": "A good seafood place.",
"author": {
"@type": "Person",
"name": "Bob Smith"
},
"publisher": {
"@type": "Organization",
"name": "Washington Times"
}
}
</script>
社区高分解答
原帖链接 · ardacarofficial · CC BY-SA 4.0
| Format | Description |
|---|---|
| JSON-LD* | A JavaScript notation embedded in a <script> tag in the <head> and <body> elements of an HTML page. The markup is not interleaved with the user-visible text, which makes nested data items easier to express, such as the Country of a PostalAddress of a MusicVenue of an Event. Also, Google can read JSON-LD data when it is dynamically injected into the page's contents, such as by JavaScript code or embedded widgets in your content management system. |
| Microdata | An open-community HTML specification used to nest structured data within HTML content. Like RDFa, it uses HTML tag attributes to name the properties you want to expose as structured data. It is typically used in the <body> element, but can be used in the <head> element. |
| RDFa | An HTML5 extension that supports linked data by introducing HTML tag attributes that correspond to the user-visible content that you want to describe for search engines. RDFa is commonly used in both the <head> and <body> sections of the HTML page. |
In the link above, it is written that schema data can be used between as well as between <body> if desired.
In addition to this article, you can check whether the schema data is correct at https://search.google.com/test/rich-results.
I tried the method you mentioned instead of you, that is, I tried to put the schema data in the <body> section and there was no problem in the test.
As a result, you can use the schema data in any way you want but my suggestion is that you take care to put it between <head> because in almost all examples in Google documents, schema data is put between <head>. In addition, wordpress plugins such as Yoast SEO also do it this way.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
