In short. Output Shopify's canonical URL with a link element whose rel is canonical and whose href contains {{ canonical_url }} inside the HTML head.
Definition: Shopify's
canonical_urlLiquid object provides the canonical URL for the current page. A theme outputs this value in thehrefattribute of a<link rel="canonical">element in the HTML<head>to declare the page's preferred URL.
Key facts
- As of 17 October 2026, Shopify's Liquid reference defines
canonical_urlas the current page's canonical URL and lists its access as global. - Shopify's SEO metadata guide shows
{{ canonical_url }}inside a canonical link element and places SEO metadata in<head>. - Shopify's layouts documentation identifies
theme.liquidas the default layout file and locates layout files in thelayoutdirectory. - Google's canonical URL documentation describes
rel="canonical"link annotations as a strong signal for canonical selection.
Where does the Liquid code go?
Shopify's SEO metadata example includes this link element inside <head>:
<link rel="canonical" href="{{ canonical_url }}" />
The expression {{ canonical_url }} outputs the object's value into the link's destination attribute. The rel="canonical" attribute identifies the relationship between the current page and that destination.
For a theme using the default layout, the relevant file is layout/theme.liquid. Shopify's layout reference explains that layouts hold content repeated across page types, including SEO metadata. It also documents custom layouts and template-level layout selection. A theme with custom layouts therefore needs a review of the layouts used by its storefront pages when checking canonical output.
What value does the object supply?
The canonical_url reference describes the value in terms of the current page. The same Liquid expression can therefore appear in shared theme code while supplying the canonical URL for the page being rendered.
Global access means the object is available to the layout: Shopify's layouts documentation explicitly says layouts can access global Liquid objects. The metadata example uses canonical_url directly, without assigning a separate variable or adding a filter. That documented expression is the starting point for outputting Shopify's supplied value.
How should the output be checked?
Review the rendered page's HTML for the canonical link, its href value and its position within <head>. Google's implementation guidance accepts this element only in the HTML head and recommends absolute URLs. The resulting destination should include the scheme and host, alongside the page path.
The same guidance recommends keeping the canonical declaration in the HTML source and preventing JavaScript from changing it. It also recommends a self-referential canonical on the preferred page itself. When reviewing existing theme code, check for competing declarations: Google advises against specifying different canonical URLs for the same page through different methods, such as a sitemap and a canonical link.
Related terms
- Canonical URL
- Where do I compare Google's selected canonical with my declared URL?
- How do I submit a Shopify sitemap to Search Console?
FAQ
Do I need to hardcode each page's canonical URL?
You can use {{ canonical_url }} in the shared layout. Shopify's object reference defines its value as the canonical URL for the current page.
Can I put the canonical link in the page body?
Place it inside <head>. Google's canonical link instructions say the element is accepted only there.
Sources
- Shopify, "Liquid objects: canonical_url", undated
- Shopify, "Add SEO metadata to your theme", undated
- Shopify, "Layouts", undated
- Google Search Central, "How to specify a canonical URL with rel="canonical" and other methods", updated 10 July 2026
Check how a page reads to answer engines. Open the GEO score analyzer