Hello! I am trying to add schema to dynamic location pages through my cms. I have tried adding the code below but it does not seem to work. Can anyone give me any help please? Thank you.
import wixSeo from 'wix-seo';
$w.onReady(function () {
$w("#locations").onReady(() => {
let item = $w("#locations").getCurrentItem();
if (item && item.LBschema) {
try {
let schemaJson = JSON.parse(item.LBschema);
console.log("Schema Data:", schemaJson);
wixSeo.setStructuredData(schemaJson);
} catch (error) {
console.error("Invalid JSON in LBschema:", error);
}
} else {
console.warn("No schema found in LBschema field.");
}
});
});
Hi,
The docs state that the assigning of SEO data should be outside the onReady function: "Note: You should always invoke the wixSeoFrontend.structuredData getter outside of the onReady() event handler to ensure receiving the proper response." https://dev.wix.com/docs/velo/apis/wix-seo-frontend/structured-data Hope that helps,
Eitan