Streaming live at 10am (PST)

Change schema according to CMS field

Hello,

Is there any way to change the schema structure (in addition to the content) depending on a CMS field?

I have a collection of articles which are different depth of information on a topic.

I would like to add a breadcrumb JSON schema in the header of the page.

I have referenced the parent articles as fields of the article.

Here is what I would like to do:

If N+1 field is set:

<script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "BreadcrumbList",
      "itemListElement": [{
        "@type": "ListItem",
        "position": 1,
        "name": "NAME_OF_N+1",
        "item": "URL_OF_N+1"
      },{
        "@type": "ListItem",
        "position": 2,
        "name": "NAME_OF_N"
	"item": "URL_OF_N"
      }]
    }
    </script>

If N+2 field is set:

<script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "BreadcrumbList",
      "itemListElement": [{
        "@type": "ListItem",
        "position": 1,
        "name": "NAME_OF_N+2",
        "item": "URL_OF_N+2"
      },{
        "@type": "ListItem",
        "position": 2,
        "name": " NAME_OF_N+1",
        "item": " URL_OF_N+1"
      },{
        "@type": "ListItem",
        "position": 3,
        "name": "NAME_OF_N"
	"item": "URL_OF_N"
      }]
    }
    </script>

I used to have the header set with dynamic data from CMS, but that only works if the schema fields are the same for all items.

I’ve tried getting an answer everywhere, I hope someone can help me.

There is no need for a read-only link as I have nothing to show, I have no solution to implement this…

Thank you

Since only one template exists for collection pages, you would need to dynamically create your schema with JavaScript (custom code). The output can be placed in the body. So it is possible if you want to invest the coding time.

1 Like

Solved it and made a tutorial here:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.