4

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>

2 Answers 2

4

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.

0

Well it's your choice, you can put it in the head as well as in the body itself. Once done, just verify your code with Structured Data Validator.

1
  • 1
    HI krypton, your answer would be better if you quoted some citations to support your statement that either is good. Commented Oct 31, 2023 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.