{% set_canonical_url %}

Use this tag to set the canonical for the current page. Note that this will override the canonical_url specified by the user, if applicable. ONLY use this method if you know what you are doing and have a good reason to do it (eg: for improved SEO on a page that contains pagination).

Syntax

{% set_canonical_url expression %}

Examples

Set the canonical url for pagination

Copy
{% if collection.page > 1 %} {% set_canonical_url entity.full_url | append: '?page=' | append: collection.page %} {% else %} {% unless entity.canonical_url is_valid %} {% set_canonical_url entity.full_url %} {% endunless %} {% endif %}