Rich Text Editor Removes JSON-LD Script After Saving – Any Workaround?
Hi everyone,
I’m facing an issue with the Shopify Rich Text Editor and couldn’t find a reliable solution.
I’m working on an industrial products website:
For SEO purposes, each product category requires a different JSON-LD schema (FAQ, Collection, Breadcrumb, etc.). Because every category has unique structured data, I can’t place a single common schema in the theme’s <head>.
My idea was to add the category-specific JSON-LD inside the page content using the Shopify Rich Text Editor. However, whenever I paste something like:
the editor accepts it initially, but after clicking Save, the entire <script> block is automatically removed.
I’ve tested this with multiple pages, and the same thing happens every time. It appears Shopify is sanitizing or stripping <script> tags from the Rich Text Editor.
My questions:
Is this expected behavior in Shopify?
Is there any supported way to output page-specific JSON-LD without hardcoding every schema into the theme?
Has anyone used metafields, metaobjects, or a custom Liquid section to inject different schema for different collection pages?
Are there any SEO-safe alternatives that don’t require editing the theme every time a new category is added?
I’d really appreciate hearing how others are managing unique structured data for large catalogs.
You’ve chosen the right word – sanitizing. There are good reasons for this.
People tend to copy/paste stuff from other sites and I remember that on several occasions some malicious code has been copied.
Usually, this is taken care by theme code, which renders different json for different templates and pages.
If this is not enough for you, an option is to use “Custom liquid” type section/block – this does minimal checks on content (if at all), so you should be able to paste your custom JSON-LD and dynamically reference page object properties to output different data for different pages.
There are Apps which will inject JSON-LD data into your pages, but frankly, if you’re thinking about code edits, then “Custom lqiuid” should cover your needs.
@Indo_Power ,
Yes this is expected Shopify strips <script> tags from the Rich Text Editor for security reasons.
For a large catalog I’d avoid storing the JSON-LD itself in the editor. Instead create a metafield (or metaobject) that stores only the structured data values (FAQs, category type, etc.) then use a single Liquid snippet to generate the JSON-LD dynamically based on the current collection or page. That way you only maintain one template and adding new categories is just a matter of filling in metafields rather than editing theme code.
Its much easier to maintain and reduces the risk of invalid or duplicate schema.
Shopify strips <script> tags from the Rich Text Editor for security reasons. A better approach is to store the JSON-LD in metafields and render it with Liquid in your theme. It’s much more scalable for large catalogs and easier to maintain than hardcoding schema for every collection.