How to add a script in header for a specific page? This can be useful to add structured data to a page displaying a blog post for example (Learn About Article Schema Markup | Google Search Central | Documentation | Google Developers), a recipe, a product, etc. The structured data snippet should be set in the header per page. For now, I only see that when we add a script in the header, it will be applied to all pages. Example of a structured data in the header section:
"headline": "Article headline",
"name": "Jane Doe",
"name": "John Doe",
Hi! It’s not mandatory to add the structured data (schema) in the header.
You can read more on how to add a schema on this related topic: Schema.org for Sitejet - #8 by Lucian_Dinu
Hope this helps!
Hi @Lucian_Dinu, thank you for your reply.
As far as I know and based on the Google Documentation, generally there are 2 ways of setting up the structured data:
- JSON-LD in the head tag
- Micodata in the body tag
And according to your answer, you are saying that I should use HTML tag element in the page body and populate it with JSON-LD code. I cannot see any Google Structured Data documentation that suggests this way. Please share your source if you found this.
Hi @Lucian_Dinu, thank you very much for pointing this out. Good to know about it.
So I would go with inserting the HTML element before the closing body tag (
</body>), in other word, right after the footer but not including in the footer (as it is per page): have you implemented it this way?
But I would keep the idea of having the possibility to add a custom header code par page.
I see that you have requested a feature that may resolve this: Dedicated <head> script area. I up voted and added the request of defining head script per page.