In the page router add possibility to specify json-ld object so that you can easily add Structured Data to your dynamic pages. Currently you can only assign it to editor pages which is highly limited for larger websites.
To clarify basically add a jsonld property to the HeadOptions. https://www.wix.com/corvid/reference/wix-router.WixRouterResponse.html#HeadOptions
Currently the only way is to inject javascript through the Tracking & Analytics which isn’t optimal.
Here is a temporary solution for anybody looking. You would add it to the “Tracking & Analytics” part as a custom tracking code under head. It calls a public api and gets the data and then injects a application/ld+json element.
I hope that Wix will get soon native support for json-LD for dynamic pages.
NOTE! Don’t use this if you are just making static pages. You can then just use the wix premade tool.
<script>
(function(){
//Add Regular Expression to match url location
if(/.../g.test(window.location.pathname)) {
//Create element to inject into head.
var script = document.createElement('script');
script.type = 'application/ld+json';
document.getElementsByTagName('head')[0].appendChild(script);
var xhr = new XMLHttpRequest();
//Use the old version xhr just in case if someone uses old browser.
xhr.onreadystatechange = function() {
if (xhr.readyState === 4){
var data = JSON.parse(xhr.responseText);
var jsonLD = {
"@context": "https://schema.org/",
"@type": "",
...
};
script.innerHTML = JSON.stringify( jsonLD );
}
};
//break part the url into array so we can use the slug.
var pathArray = window.location.pathname.split('/');
//Edit the index to match the location of the slug.
xhr.open('GET', 'https://yourendpoint.com/api/'+pathArray[3]+'/);
xhr.send();
}
</script>
I agree. Highly needed for Dynamic Pages.
Agreed as well. This seems like quite the oversight considering it’s available with static pages. Thanks to Bjorn for the workaround, but I’d imagine that hosting a public API to inject the data will be more technically involved than many would be comfortable with.
This has killed a potential project for me.
Hey! This is now possible
Now possible! We can use the Wix SEO API!
Can you elaborate? What’s necessary to implement this?
Documentation:
https://www.wix.com/corvid/reference/wix-router.WixRouterResponse.html#HeadOptions
Use structuredData to add application/ld+json script element