Add structured data (Schema.org JSON-LD) to your Shoporama theme
A complete guide to JSON-LD structured data in a Shoporama theme, with Smarty examples for Product, Store, BreadcrumbList, and AggregateRating using the correct safe methods.
Structured data (Schema.org) helps Google and other search engines understand the content of your pages. For an online store, it is especially useful to mark up products, store information, breadcrumbs, and product reviews, so you can get "rich snippets" in the search results with details such as price, stock status, and star ratings.
Tip: Shoporama automatically adds basic Schema.org markup for products through our built-in SEO features. Read about automatic structured data and SEO in Shoporama. This article is for you if you want to build or extend the markup yourself in your theme.

What is structured data?
Structured data is a standardized way of describing a page's content in a format search engines understand. JSON-LD is the recommended format, and it goes in a <script type="application/ld+json"> tag. It doesn't change how the page looks, but it gives search engines structured information they can use for rich snippets.
The right safe methods on SafeProduct, SafeWebshop, and SafeCompany
Before you build your own JSON-LD markup, it's important to know which safe methods actually exist on the objects in a Shoporama theme. These are the stable methods you can use in Smarty.
On $product (SafeProduct):
- getName(), getDescription(), getOwnId(), getGtin(), getMpn(), getBrandName()
- getPrice(), getSalePrice(), getRealPrice(), getLowest30DayPrice()
- getStockCount(), getIsInStock(), and getAllowNegativeStock()
- getImage() and getImages() return SafeImage with getSrc($w, $h, $type)
- getAvgRating($no_round), getReviewCount(), getProductReviews($limit)
- getUrl() returns the product's relative path
On $webshop (SafeWebshop):
- getName(), getDescription(), getCurrency(), getUrl(), getLogo()
- getCompany() returns SafeCompany
On $webshop->getCompany() (SafeCompany):
- getName(), getRegNr(), getEmail(), getPhone()
- getAddress(), getZipcode(), getCity(), getCountry()
Note: Don't use $product->getStock(), $product->getAverageRating(), $webshop->getCurrencyCode(), $webshop->getDomain(), $webshop->getEmail(), or $webshop->getPhone(). They don't exist as safe methods, and your theme will fail. Use getStockCount(), getAvgRating(), getCurrency(), getUrl(), and getCompany()->getEmail()/getPhone() instead.
Escaping: use @json_encode, not escape:javascript
JSON-LD is JSON, and JSON has its own rules for how special characters are written. This is by far the most common reason Google rejects otherwise correct markup, so it's worth getting right before you write your first block.
Don't use |escape:'javascript' in JSON-LD. It turns an apostrophe into \', which is valid in JavaScript but not in JSON, where that escape sequence doesn't exist at all. A single product with an apostrophe in its name, such as "Bo's Coffee", is therefore enough for Google to discard the entire block, and the page loses price, stock status, and stars all at once. In Search Console, it shows up as "Bad escape sequence in string".
Use |@json_encode instead. It outputs the value as a complete JSON string including the quotation marks, so you need to remove the quotation marks from your template:
Wrong: "name": "<{$product->getName()|escape:'javascript'}>",
Right: "name": <{$product->getName()|@json_encode}>,
This handles apostrophes, quotation marks, backslashes, and line breaks correctly. Line breaks are worth noting: a review written over several lines breaks the JSON if it isn't escaped, and neither |escape nor <{strip}> catches it. On top of that, the modifier escapes forward slashes, so a </script> in a product name can't close your script block too early.
- If the field can be empty, add |default:"" before it, for example <{$product->getOwnId()|default:""|@json_encode}>. Otherwise the result is null instead of an empty string.
- If HTML needs to be removed first, add |strip_tags:true before it, so |strip_tags:true|@json_encode.
- There is no |escape:'json' in Smarty. If you use it, no escaping happens at all.
- Numbers and fixed values, such as price, currency, and schema.org URLs, should still be in regular quotation marks. They don't contain special characters.
- |escape:'javascript' is still the right choice in regular JavaScript, for example in a dataLayer push. It's only wrong in JSON-LD.
Product markup (Product)
The most important type for an online store is Product markup. Add the block to your product template (typically product/view.html):
<{assign var="availability" value=$product->getStructuredDataAvailability()}>
<{assign var="availabilityStarts" value=$product->getStructuredDataAvailabilityStarts()}>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Product",
"name": <{$product->getName()|@json_encode}>,
"description": <{$product->getDescription()|strip_tags|@json_encode}>,
"sku": <{$product->getOwnId()|@json_encode}>,
<{if $product->getGtin()}>
"gtin": <{$product->getGtin()|@json_encode}>,
<{/if}>
<{if $product->getMpn()}>
"mpn": <{$product->getMpn()|@json_encode}>,
<{/if}>
<{if $product->getBrandName()}>
"brand": {
"@type": "Brand",
"name": <{$product->getBrandName()|@json_encode}>
},
<{/if}>
<{if $product->getImage()}>
"image": "<{$product->getImage()->getSrc(800, 800, 'fit')}>",
<{/if}>
"offers": {
"@type": "Offer",
"url": "<{$webshop->getUrl()}><{$product->getUrl()}>",
"price": "<{$product->getRealPrice()|string_format:"%.2f"}>",
"priceCurrency": "<{$webshop->getCurrency()}>",
"availability": <{$availability|@json_encode}><{if $availabilityStarts}>,
"availabilityStarts": <{$availabilityStarts|@json_encode}><{/if}>
}
}
</script>
Key points in the example:
- The price comes from getRealPrice(), so any sale price and discount are included, and VAT is added.
- The currency comes from getCurrency() on $webshop (it returns, for example, "DKK" or "EUR").
- The stock status comes from getStructuredDataAvailability(), which returns the finished schema.org URL: https://schema.org/InStock, OutOfStock, or BackOrder. The method uses exactly the same logic as our Google Shopping feed, so the product page and the feed always say the same thing. Don't build it yourself from getIsInStock() and getAllowNegativeStock(): that combination misses the fact that the store itself decides whether backorder products are sent as "backorder", and then you get exactly the mismatch you wanted to avoid.
- getStructuredDataAvailabilityStarts() returns the expected delivery date of a backordered product, which is the availabilityStarts field. It returns an empty value when the product isn't on backorder, or when you haven't filled in a lead time under Google Shopping, so wrap it in an <{if}> as in the example.
Important if you use Google Shopping: Google compares the stock status on the product page with the one you send in the product feed. If the two don't match, Google can disapprove the product, so it disappears from both Shopping ads and the free product listings. When you use getStructuredDataAvailability(), the two can't contradict each other, because the feed and the product page are built on the same method. If you write your own stock status logic, you risk the page saying "out of stock" about a product the feed reports as available to buy. Shoporama's own themes already handle this. Read more in Set up a Google Shopping feed.
Prior price (the Omnibus Directive)
If the product is on sale, Google recommends showing the lowest price from the last 30 days as the reference price. Use getLowest30DayPrice() to get it. It returns null if there isn't enough price history.
Product reviews (AggregateRating)
If you use Shoporama's built-in review system, you can add an average rating directly in the Product markup. This can give you stars in Google's search results. Insert the block inside the Product object:
<{if $product->getReviewCount() > 0}>
,
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "<{$product->getAvgRating(true)|string_format:"%.1f"}>",
"reviewCount": "<{$product->getReviewCount()}>"
}
<{/if}>
Passing true to getAvgRating() returns an unrounded average, which Google prefers (for example 4.3 instead of just 4).
Store information (Store / LocalBusiness)
You can also mark up the store itself, for example in your footer template. Get the contact details from $webshop->getCompany(), so the information you have already entered under Company → Company information is included automatically:
<{$company = $webshop->getCompany()}>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Store",
"name": <{$webshop->getName()|@json_encode}>,
"url": "<{$webshop->getUrl()}>"
<{if $company}>
,
<{if $company->getEmail()}>
"email": <{$company->getEmail()|@json_encode}>,
<{/if}>
<{if $company->getPhone()}>
"telephone": <{$company->getPhone()|@json_encode}>,
<{/if}>
"address": {
"@type": "PostalAddress",
"streetAddress": <{$company->getAddress()|@json_encode}>,
"postalCode": <{$company->getZipcode()|@json_encode}>,
"addressLocality": <{$company->getCity()|@json_encode}>,
"addressCountry": <{$company->getCountry()|@json_encode}>
}
<{/if}>
<{if $webshop->getLogo()}>
,
"logo": "<{$webshop->getLogo()->getSrc(400, 400, 'fit')}>"
<{/if}>
}
</script>
Make sure your company information is filled in correctly in the admin under Company → Company information. If you have a physical store, you can use LocalBusiness or a more specific subtype (for example ClothingStore) as @type.
Breadcrumbs (BreadcrumbList)
On product and category pages, it's good SEO practice to mark up breadcrumbs. Here is an example for a product with a main category:
<{if $product->getMainCategory()}>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"name": <{$webshop->getName()|@json_encode}>,
"item": "<{$webshop->getUrl()}>"
},
{
"@type": "ListItem",
"position": 2,
"name": <{$product->getMainCategory()->getName()|@json_encode}>,
"item": "<{$webshop->getUrl()}><{$product->getMainCategory()->getUrl()}>"
},
{
"@type": "ListItem",
"position": 3,
"name": <{$product->getName()|@json_encode}>,
"item": "<{$webshop->getUrl()}><{$product->getUrl()}>"
}
]
}
</script>
<{/if}>
Test your structured data
Use the tools from Google and Schema.org to validate your markup before you go live:
- Rich Results Test checks whether your markup is eligible for rich snippets in Google
- Schema Markup Validator validates the JSON-LD syntax
- In Google Search Console, you can see reports on your products and rich results once the pages have been crawled
Tip: If you have already enabled automatic structured data in Shoporama, make sure you avoid duplicates. Check what is already on the page before you add your own markup.
Frequently asked questions
Do I need to code JSON-LD myself at all?
No, not necessarily. Shoporama has built-in automatic structured data for products, and it covers most needs. Coding it yourself is mainly relevant if you want to add more fields or use a more specific @type, for example for hotels, restaurants, or events.
Which schema types can I use besides Product?
In a Shoporama theme, you can build any Schema.org type that exists as JSON-LD. The most common ones for online stores are Product, Offer, AggregateRating, Review, BreadcrumbList, Store, LocalBusiness, Organization, WebSite with SearchAction, and FAQPage for static FAQ pages.
Why do I get errors in the Rich Results Test?
Typical errors are missing fields (for example price without priceCurrency), incorrectly formatted numbers, or special characters that break the JSON syntax. By far the most common cause is escaping: run all text values through |@json_encode and not |escape:'javascript', which turns an apostrophe into invalid JSON. See the section on escaping further up.
How long does it take before I see stars in Google?
Google has to crawl the page again before your new markup is used. This can take anywhere from a few days to a couple of weeks. In Search Console, you can request faster reindexing of individual pages.
Does it affect my rankings in Google?
Structured data isn't a direct ranking factor, but rich snippets with details such as price and stars make your search result more visible and can increase your click-through rate. Over time, it helps improve your overall SEO.
How do I handle VAT in the price field?
Use getRealPrice(), which returns the price incl. VAT. That is the price customers see in the store, and the one Google expects in Product markup on a B2C store. If you need to show prices excl. VAT (B2B), use getPriceExVat() instead.
Do I need reviews before I show AggregateRating?
Yes. Only add AggregateRating if the product actually has reviews. The example above checks getReviewCount() > 0, so the markup isn't added to products without reviews. Fake or empty ratings can trigger a penalty from Google.
Where do I find my company information for the Store markup?
Go to Company → Company information in the admin. The details you fill in here are available through $webshop->getCompany() in your theme, so the Store block is filled in automatically.
Where should I place the JSON-LD on the page?
You can place it either in <head> or in <body>. Google accepts both. On product pages, it's common to place it at the bottom of the product template.
My store sells in several languages. Do I need markup for each language?
Yes, names and descriptions in the markup should match the page the customer sees. Since $product->getName() and $product->getDescription() automatically return the translated text for the active language, this happens automatically when you use the examples here.
Need help with structured data? Contact us at support@shoporama.dk.
Related articles
SEO in Shoporama: a complete guide to the SEO features
A complete guide to the SEO features in Shoporama, from meta titles, meta descriptions, and the XML sitemap to keyword analysis, Google Shopping,...
Product reviews: collect, approve, and show customer reviews
Learn how to use product reviews in Shoporama. Collect customer reviews and photos automatically, moderate them, and show star ratings on your...
Smarty template variables in Shoporama themes
Overview of the global and page-specific Smarty variables available in Shoporama themes, such as the cart, customer, campaigns, products, and...
Implement ecommerce tracking in a Shoporama theme
Developer guide to ecommerce tracking in a Shoporama theme: the data layer, Google Tag Manager, custom events, and correct product IDs with...
Add a blog to your online store
A complete guide to the blog feature in Shoporama: create posts, schedule publishing, link products, optimize for search engines, and use dynamic...
Price history and the Omnibus Directive: show the prior price
Shoporama automatically logs price changes and calculates the correct prior price under the Omnibus Directive (EU 2019/2161). The standard themes...
How to set noindex on a page, product, or category
How to set noindex on products, categories, pages, landing pages, and blog posts in Shoporama, so they are not shown in Google's search results.
Set up your Google Shopping feed in Shoporama
How to set up and customize the built-in Google Shopping feed in Shoporama: Google product categories, custom labels, product IDs and catalog...
Show star ratings in Google Shopping with product reviews
How to show your product reviews as star ratings in Google Shopping with Shoporama's built-in product reviews feed: enabling it, Google's...
Product IDs and catalog matching: match your ads to your product feed
Learn which product ID Shoporama's tracking sends, why it always matches the Google Shopping feed, what catalog matching means for your Meta and...
Related features
JSON-LD
JSON-LD is Google's recommended format for structured data. Learn about schema.org, Product markup, rich snippets, and automatic JSON-LD in...
Rich snippets
Rich snippets show stars, prices, and stock status directly in Google's search results. Learn the types, benefits, and how Shoporama adds...
Structured data
Structured data uses schema.org markup to give Google precise product information. Learn about JSON-LD, schema types, and Shoporama's automatic...
Structured data: automatic Schema.org markup
Automatic Schema.org markup for products, reviews, breadcrumbs, and business info. Rich snippets in Google with star ratings and prices. Included.
Open Graph tags (OG tags)
Open Graph tags control how your links appear on Facebook, LinkedIn, and Twitter. Learn the key OG tags, image sizes, and how Shoporama generates...
SEO (Search Engine Optimization)
SEO brings your online store free traffic from Google. Learn about technical SEO, on-page optimization, link building, and Shoporama's built-in SEO...
SEO in Shoporama – get found on Google
Built-in SEO in Shoporama: fast loading, control over titles and meta descriptions, dynamic tags, automatic 301 redirects, XML sitemap, noindex,...