Sub topic 16
Keeping markup correct over time
This chapter assumes you can write JSON-LD with @context, @type, nested entities, and @graph. You should also know how to embed it in a page and run the validators. Here you will learn why markup goes wrong after launch and how to prevent it.
Why markup drifts
Structured data is a second copy of facts that already appear on the page. When the visible price changes and the markup does not, the two disagree. Search engines compare them, and a mismatch can make the page ineligible for rich results. Google's guidelines also say the markup must describe content that users can see.
Drift usually has one of these causes:
- A template edit changes the visible content but not the script element.
- A price, stock level, or date is hard-coded in the markup.
- A redesign removes a section, such as reviews, that the markup still describes.
- A vocabulary or search engine requirement changes, and old markup no longer qualifies.
Common pitfalls
| Pitfall | Effect | Fix |
|---|---|---|
| Markup for content not on the page | Rich result may be withheld, or a manual action may apply | Mark up only what visitors can see |
| Stale `price` or `availability` | Search results show wrong data | Build the markup from the same data as the page |
| Missing required properties | Page is not eligible for the rich result | Check the current Google documentation for the type |
| Copy-pasted `@id` values | Two pages claim to be the same entity | Derive each `@id` from the page URL |
| Wrong value format | Property is ignored | Use ISO 8601 dates, a currency code, and a price string |
| Unescaped data in the script | Broken JSON or injected markup | Escape `</` when generating output |
Keep one source of truth
The most reliable fix is to generate markup from the same data that renders the page. The example below builds the Product markup from one record and uses that record for the visible text too.
import json
record = {
"name": "Pour-Over Kettle",
"price": "39.90",
"currency": "EUR",
"in_stock": True,
"url": "https://example.com/products/kettle",
}
def product_jsonld(item):
availability = "InStock" if item["in_stock"] else "OutOfStock"
data = {
"@context": "https://schema.org",
"@type": "Product",
"name": item["name"],
"offers": {
"@type": "Offer",
"price": item["price"],
"priceCurrency": item["currency"],
"availability": "https://schema.org/" + availability,
"url": item["url"],
},
}
payload = json.dumps(data, ensure_ascii=False).replace("</", "<\\/")
return '<script type="application/ld+json">' + payload + "</script>"
print(product_jsonld(record))When stock changes, the visible label and the markup change together.
A maintenance routine
- Validate templates in the Schema Markup Validator and the Rich Results Test before each release.
- Add an automated check that parses each script element as JSON and confirms required properties exist.
- Watch the enhancement reports in Google Search Console. They list errors and warnings by type across your site.
- Review markup when you redesign a template or remove a page section.
- Re-read the search engine documentation for each type you use a few times a year, because required and recommended properties change.
Retiring and moving pages
When a product is discontinued, either keep the page with OutOfStock availability or remove the page and its markup together. If a URL changes, update every @id and url that refers to it, including the Organization and WebSite nodes in a shared @graph.
Exercise
A product page shows "Sold out", but its JSON-LD still says "https://schema.org/InStock". The Rich Results Test shows no errors. Why is this still a problem, and what is the lasting fix?
Show answer
The validator checks syntax and property rules, not whether the markup matches the visible page. The mismatch breaks search engine guidelines and can show wrong data in results. The lasting fix is to generate both the visible label and the availability value from the same stock data, so they cannot diverge.
Exercise
Name two checks you can automate so that broken structured data is caught before release.
Show answer
Parse each script element as JSON and fail the build on a syntax error. Confirm that required properties for each type, such as name and offers for a Product, are present. Comparing markup values with the rendered page values is also valid.