What is the best way to add JSON-LD schema to pages that has a specific component | Community
Skip to main content
Level 2
December 11, 2023
Solved

What is the best way to add JSON-LD schema to pages that has a specific component

  • December 11, 2023
  • 2 replies
  • 3391 views

Hello! I am new to AEM, and I need to figure out how to add schema structured data (in JSON-LD format) to all pages that contain one of our custom components.

 

I know similar questions have been asked before, but the answers weren't very detailed and a bit unclear. I'd like to know about the different approaches, and which one would be the best/most efficient. 

 

Also it's important to note that we already have a lot of existing pages with this component, so I'm hoping for a solution that'll apply to those pages as well without having to do any re-authoring.  

 

I would also appreciate any links to resources that may be helpful. Thanks!

Edit: One other thing I am confused about, is it incorrect to add the json-ld schema data to the component itself? This seems like it would be a straightforward solution, but no one seems to recommend it. 

Best answer by arunpatidar

Hi @ishaja 
You can this logic to page component's head section

e.g

<sly data-sly-use.scriptPojo="${'com.myproj.core.models.GenerateApplicationJson'}"> <script type="application/ld+json"> ${scriptPojo.getJson @ context='styleScript'} </script> </sly>

 

 

2 replies

arunpatidar
Community Advisor
Community Advisor
December 12, 2023

Hi @ishaja 
Please check https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/schema-markup-via-json-ld/m-p/270680 

 

You can use AEM custom component, to generate JSON-LD

Arun Patidar
IshaJaAuthor
Level 2
December 12, 2023

Hi @arunpatidar,

 

Thanks for responding, but my main question was how to add the JSON-LD to pages that contain a specific component. We have hundreds of pages that may contain this component, so manually adding it in through a custom component isn't an ideal option.

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
December 13, 2023

Hi @ishaja 
You can this logic to page component's head section

e.g

<sly data-sly-use.scriptPojo="${'com.myproj.core.models.GenerateApplicationJson'}"> <script type="application/ld+json"> ${scriptPojo.getJson @ context='styleScript'} </script> </sly>

 

 

Arun Patidar
kautuk_sahni
Community Manager
Community Manager
February 2, 2024

@ishaja Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni