大网数据广告活动
网站运营与故障问答

Where to put schema markup code. In <head> or <body> tag?

· 52CE 我爱测

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 fin…

问题原文

原帖链接 · 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

https://developers.google.com/search/docs/appearance/structured-data/intro-structured-data#supported-formats

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2023-10-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。