Adding Custom JSON-LD Script to Page Types

Anne Kercher asked on August 9, 2021 17:06

Hello. We are interested in adding a custom script using JSON-LD and Schema.org to the head of our Kentico portal engine site pages (v11). We would like to use this to assist with our custom search crawler to categorize, filter, and index our pages.

Below is an example of the script that would be on one of our "Product" pages. However, this script will vary based on the page type. Is there a recommended way to add this script automatically with the appropriate data to each of our pages? Should we use a transformation for each page type? Or a custom module or webpart?

Recent Answers


Liam Goldfinch answered on August 9, 2021 23:02

I would create a custom webpart.

The webpart should utilise data from the Current Document, and generate the appropriate JSON-LD structured data snippet based on the Page Type. Or you could have multiples webparts - one for each Page Type.

1 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on August 10, 2021 07:08

Hi Anne,

I'd agree with Liam, custom web part would be the best option. Within its code, you can check CurrentDocument's type and based on this select strategy for generating Schema.org markup. The only important thing to mention, it doesn't have to be in HEAD, it could be in BODY tag, no problem. Check out this comment, for example.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.