How do I add schema markup on Shopify or WordPress?
Check what you already have
Before adding anything, run one of your product or blog pages through the Rich Results Test. Your theme or a plugin may already output some structured data, and you want to know what is there before adding more.
Shopify's own SEO overview says Shopify handles structured data automatically, that its themes include schema markup for products, and that structured data implementation is built into Shopify themes. So on Shopify, the first job is usually checking and extending, not starting from nothing.
Adding schema markup on Shopify
For markup beyond what your theme outputs, you edit the theme code. Shopify's help centre gives these steps:
- Duplicate your theme first, so you have a backup you can go back to.
- From your Shopify admin, go to Online Store.
- Click the horizontal menu icon next to the theme, then select Edit code.
- Add your JSON-LD inside a
<script type="application/ld+json">tag in the relevant template or section, then click Save.
Shopify also gives theme developers a Liquid filter called structured_data. It outputs schema.org JSON-LD for a product (as Product, or ProductGroup when the product has variants) or an article (as Article). The filter does not add the script tag itself, so you wrap it, for example <script type="application/ld+json">{{ product | structured_data }}</script>.
Shopify's help centre notes two cautions. It suggests only editing code if a Shopify app or the theme editor cannot make the change, and it warns that if your code changes conflict with a theme update, your code changes are removed in the updated copy. Keep a note of what you added.
Adding schema markup on WordPress
There are two routes on a self-hosted WordPress site.
Using a plugin
Many plugins in the WordPress plugin directory can add structured data. WordPress's documentation explains how to install one: go to Plugins, then Add New (labelled Add New Plugin in recent versions), search, click Install Now, then Activate. It also says plugins in the directory are of varying quality, so check whether the listing says it is compatible with your version of WordPress and look at the Support tab before installing. Keep plugins updated, which WordPress says helps your site's security and performance.
Adding code yourself
WordPress has an action hook called wp_head, which prints scripts or data in the head of the page. You can hook a function to it that outputs your JSON-LD:
function mysite_schema() {
echo '<script type="application/ld+json">{"@context":"https://schema.org","@type":"Organization","name":"Example Ltd","url":"https://www.example.co.uk"}</script>';
}
add_action( 'wp_head', 'mysite_schema' );
Put code like this in a child theme's functions.php, not the parent theme. WordPress's theme handbook explains that a child theme lets the parent theme be updated without losing your modifications, and that the child's functions.php loads in addition to the parent's.
Test before and after publishing
- Run the page through the Rich Results Test after every change. Google describes it as the official Google tool for testing structured data.
- For schema.org types with no Google rich result, use the Schema Markup Validator.
- Once live, use the URL Inspection tool in Search Console to confirm Google found the markup.
- Only mark up content that is visible on the page. Google's guidelines say structured data must be a true representation of the page content.
Our Schema tools can also check the structured data on a Shopify or WordPress page once it is live.
Sources
- Shopify Help Center: SEO overview (structured data in themes)
- Shopify Help Center: Editing theme code
- Shopify.dev: Liquid structured_data filter
- WordPress Documentation: Manage plugins
- WordPress Developer Resources: wp_head hook
- WordPress Theme Handbook: Child themes
- Google Search Central: Introduction to structured data markup
- Google Search Central: Structured data testing tools
- Google Search Central: General structured data guidelines
Frequently asked questions
Does Shopify add schema markup automatically?
Yes, to a point. Shopify's SEO overview says its themes automatically include schema markup for products and that structured data is built into Shopify themes. What is included depends on your theme, so run a product page through Google's Rich Results Test to see what is already there before adding more, and only add what is missing.
Will a WordPress theme update remove my schema code?
It can if you added the code to the parent theme's files. WordPress's theme handbook recommends a child theme, which lets the parent theme be updated without losing your modifications. Put your wp_head function in the child theme's functions.php, or use a plugin instead, and test the page again after any theme or plugin update.