Example of dynamically creating JSON-LD to create Google Rich Cards in Meteor?
I would like to see if somebody could post an example of how to dynamically create a JSON-LD to create a google rich card? I had read issues here and stack overflow posts and I think it's possible but I haven't figured it out how. I would really appreciate if somebody could show me an example of how to implement this.
This is what I've so far:
<Helmet>
<script type="application/ld+json">
{
{
"@context": "http://schema.org",
"@type": "WebSite",
"name": ${this.state.title.toString()},
"url": ${this.state.url.toString()},
"description": ${this.state.body.toString()},
"image": ${this.state.imgUrlGal.toString()}
}
}
</script>
</Helmet>
Thanks
see Reference Guide https://github.com/nfl/react-helmet
<Helmet>
<script type="application/ld+json">{`
{
"@context": "http://schema.org",
"@type": "WebSite",
"name": "${this.state.title}"
}
`}</script>
</Helmet>
@vanvuongngo , if we have collection , for example multiple name, need to bind dynamically. how we can do.
@vanvuongngo
I need below structure
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [{
"@type": "ListItem",
"position": 1,
"item": {
"@id": "https://example.com/books",
"name": "Books",
"image": "http://example.com/images/icon-book.png"
}
},{
"@type": "ListItem",
"position": 2,
"item": {
"@id": "https://example.com/books/authors",
"name": "Authors",
"image": "http://example.com/images/icon-author.png"
}
},{
"@type": "ListItem",
"position": 3,
"item": {
"@id": "https://example.com/books/authors/annleckie",
"name": "Ann Leckie",
"image": "http://example.com/images/author-leckie-ann.png"
}
},{
"@type": "ListItem",
"position": 4,
"item": {
"@id": "https://example.com/books/authors/ancillaryjustice",
"name": "Ancillary Justice",
"image": "http://example.com/images/cover-ancillary-justice.png"
}
}]
}
</script>
itemListElement": [{ "@type": "ListItem", "position": 1, "item": { "@id": "https://example.com/books", "name": "Books", "image": "http://example.com/images/icon-book.png" }
Dynamically need to inject into script tag. any suggestion ?
Apologies mate but you need to learn react. This isn't a helmet question. This is a question about how to use JSX.
My website is https://israel-escorts.com/. Which are kind of rich cards can be used for my site?
SEO
structured-data
https://developers.google.com/search/docs/guides/intro-structured-data
https://search.google.com/structured-data/testing-tool
JSON-LD
https://json-ld.org/
https://en.wikipedia.org/wiki/JSON-LD
Why not to write more elegant way:
<script type="application/ld+json">{JSON.stringify(seo.structuredData)}</script>
I am following @themondays approach.
I am getting two script elements in <head>.

They have different values. I guess it is due to re-renders with a different value. Is there a way to replace the firsts ones with the last one?
@PolGuixe I think you can add key prop in your script tag, like
<script key="my-structured-data" type="application/ld+json">{JSON.stringify(seo.structuredData)}</script>
Just my 2 cents, most of the examples here are wrong. If you want your JSON minified and not encoded to HTML you should use this:
<script type="application/ld+json" dangerouslySetInnerHTML={{__html: JSON.stringify(myData)}}></script>.
@igo have you tried using Helmet around script tag? Helmet accepts a encodeSpecialCharacters option that can be set to false.
<Helmet encodeSpecialCharacters={false}>
<script type="application/ld+json">{JSON.stringify(someStructuredData)}</script>
</Helmet>