2

I have a page describing a tourist attraction (TouristAttraction). Since I also want to add breadcrumb informations, I would need to add WebPage as well.

What is the way to go, for adding both infos:

  1. Should I use WebPage and add the TouristAttraction as mainEntity?
  2. Should I create 2 separate JSON-LD script blocks with separate WebPage and TouristAttraction blocks?

And when using 2 entities:

  1. Do I have to provide the main informations (name, image, rating, etc.) in both entities, or just in one (which one)?
bernhardh
  • 3,137
  • 10
  • 42
  • 77

3 Answers3

9

@unor's answer is almost correct, but if you are doing it for google serp's, only splitting it up into separate json-blocks (or graph notation) will give the best result.

Let's say you want to use the Recipe entity to get google's rich snippet for Recipies in the serps you would do it like so:

<script type="application/ld+json">
{
  "@context":"https:\/\/schema.org",
  "@type":"Recipe",
  "name":"Example",
  "image":"https:\/\/www.example.com"
}
</script>

In google's Structed Data Testing Tool you will get a preview button for it:

enter image description here

If you now want to add other information from other entities (like breadcrumb), you have to use separate JSON-LD blocks, otherwise you will not get the preview button. So for example

<script type="application/ld+json">
{
    "@context": "http://schema.org",
    "@type": "ItemPage",
    "breadcrumb": {
        "@type": "BreadcrumbList"
    },
    "mainEntity": {
        "@type":"Recipe",
        "name":"Example",
        "image":"https:\/\/www.example.com"
    }
}
</script>

is valid, but will not show preview button.

But if you split it up, it will show to separate entities and also the preview button:

<script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "ItemPage",
        "breadcrumb": {
            "@type": "BreadcrumbList"
        }
    }
</script>
<script type="application/ld+json">
{
    "@context": "http://schema.org",
        "@type":"Recipe",
        "name":"Example",
        "image":"https:\/\/www.example.com"
    }
}
</script>

Same works for Array-Notation:

<script type="application/ld+json">
[
    {
        "@context": "http://schema.org",
        "@type": "ItemPage",
        "breadcrumb": {
            "@type": "BreadcrumbList"
        }
    },
    {
        "@context": "http://schema.org",
         "@type":"Recipe",
         "name":"Example",
         "image":"https:\/\/www.example.com"
    }
]
</script>

And graphs:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@graph": 
    [
        {
            "@type": "ItemPage",
            "breadcrumb": {
                "@type": "BreadcrumbList"
            }
        },
        {
            "@type":"Recipe",
            "name":"Example",
            "image":"https:\/\/www.example.com"
        }
    ]
}
</script>

Credits goes to @unor (see also How do you combine several JSON-LD markups?)

bernhardh
  • 3,137
  • 10
  • 42
  • 77
  • I have three questions/remarks: 1. If you don't get a preview button in the tool, does this mean you won't get a rich snippet in actual search results too? 2. Also, if you add a `mainEntity` to a `WebPage`. (e.g. a `Blogposting`) The tool still asks you to add `MainEntityOfPage` to the `BlogPosting`. Which seems a bit weird to me. 3. If you add multiple top level entities. Aren't you letting Google decide which it will take as the main entity for that page? So even though you won't get a preview button in the tool, isn't it still better to explicitly point the main entity out? – milosa Aug 11 '18 at 09:23
  • I have no idea, if Google will use the data as expected, if the preview button is not show. Thats why I suggests to use the other variants (array, graph, etc). – bernhardh Aug 14 '18 at 10:59
2

Using mainEntity is of course preferable to not using it, as more data (if accurate) is generally better than less data.

But you can use mainEntity in both cases, no matter if you use one or multiple script elements. In the first case, you can simply nest the items. In the second case, you can make use of URI references.

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "ItemPage",
  "breadcrumb": {
    "@type": "BreadcrumbList"
  },
  "mainEntity": {
    "@type": "TouristAttraction"
  }
}
</script>
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "ItemPage",
  "breadcrumb": {
    "@type": "BreadcrumbList"
  },
  "mainEntity": {"@id": "#content"}
}
</script>

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "TouristAttraction",
  "@id": "#content"
}
</script>

(And there are other ways, too.)

No matter which way you go, the ItemPage and the TouristAttraction are different entities, of course. So if you add aggregateRating to the ItemPage, it’s for the rating of the page, and if you add it to the TouristAttraction, it’s for the rating of the attraction. For properties that would take the same value, it can still make sense to add them to both entities, as a consumer might only be interested in one of the entities and ignore the other one.

unor
  • 92,415
  • 26
  • 211
  • 360
  • Please see my own answer based on yours, since your answer is maybe not totally correct? – bernhardh Aug 09 '18 at 11:01
  • @bernhardh: Thanks for the note :) What my answer shows should be correct use of Schema.org and JSON-LD. Consumers of the structured data (like Google Search) might add any restriction on top of that, possibly even creating conflicts (if one consumer wants it this way, and another consumer that way). As your question didn’t ask about a specific consumer, I wouldn’t want to make my answer specific to one. -- That said, I wouldn’t be sure that a missing "Preview" button on Google’s SDTT is a sufficient indicator that Google Search won’t display a rich result -- would need live testing. – unor Aug 09 '18 at 16:44
  • Thanks you very much. I totally agree, that in general, all solutions are correct and fine, but in my case, I only add schema data for better google serp placement and clickrates (like probably most of the user). – bernhardh Aug 10 '18 at 09:55
0

WebPage is implicit for a Web Page, so you don't need to specifically add it.

You can define a BreadcrumbList as a top level entity and systems will understand it is an entity within the WebPage.

For the entity that you want to be considered main, you can also make it a top level entity and state it is the main entity using mainEntityOfPage with its id set to the URL of the page.

Tony McCreath
  • 2,882
  • 1
  • 14
  • 21