chalk icon indicating copy to clipboard operation
chalk copied to clipboard

Adding Structured Data

Open xRahul opened this issue 6 years ago • 6 comments

Hey guys, I have recently started to dive deep into the SEO aspects of the theme. As I can see, there is no structured data for List of Articles, each article, author etc. Adding some basic structured data can really enhance the website in search results when users are using this theme. We can use schemas like BlogPosting, Article etc on the pages and give them a boost in the search. Reference commit

xRahul avatar Dec 27 '17 19:12 xRahul

This is a good idea, it is standardized as far as I know and it makes sense. Is there any way of adding the tags without javascript? I used to do this with html tags in the <head>, not sure if that's still possible.

migueldemoura avatar Dec 27 '17 20:12 migueldemoura

No javascript is required to add it. The json-ld format uses the script tag, but that's just semantics. Check out the structured data page by google It is just a properly formatted json wrapped in script tags. It's the default standard nowadays

xRahul avatar Dec 27 '17 20:12 xRahul

What I knew before was https://www.w3.org/TR/microdata. Could you place the json in a separate .js file? That way you get better caching and it doesn't interfere with a proper CSP definition.

migueldemoura avatar Dec 27 '17 22:12 migueldemoura

microdata is an older format and search engines are moving towards json-ld format now.

Google recommends using JSON-LD for structured data whenever possible.

Also, it's structured data for the page, so moving it to a separate file doesn't make sense. We can add it in the <Head> tag just like the og and twitter tags we have. It can also be added in the body. Also, what do you mean by CSP definition? I'm unfamiliar with the term.

xRahul avatar Dec 28 '17 04:12 xRahul

Yes yes, I read their recommendation.

We can add it in the tag just like the og and twitter tags we have. How would that look like?

CSP "is an added layer of security that helps to detect and mitigate certain types of attacks, including Cross Site Scripting (XSS) and data injection attacks." The correct way of using it would break the inline scripts (w/o nounces), hence my question about moving it to another file. This should be a non-issue for most users, just asking as myself and a couple others I know will have to find a workaround :)

All in all this a great addition!

migueldemoura avatar Dec 28 '17 15:12 migueldemoura

As this is a theme, I did not add too much information in the structured data, but I've made it extensible so that users can add their own.

xRahul avatar May 21 '18 15:05 xRahul