
# How can I set up canonical tags?

> Two worked examples: a self-referencing canonical tag, and a Shared Field group that lets editors point a page at an alternative canonical URL.

URL: https://www.hannonhill.com/cascadecms/latest/articles/developing-in-cascade/seo/set-up-canonical-tags.html
category: Developing in Cascade
article-type: how-to
content-kind: faq
release-availability: all
tags: templates, data-definitions, velocity
updated: 2026-10-06

This article gives two sample methods for configuring canonical tags. They're examples, and may need additional development depending on your needs.

## Self-referencing canonical tags

1.  Create a Velocity [Format](https://www.hannonhill.com/cascadecms/latest/articles/developing-in-cascade/script-formats/index.html) containing:
    ```velocity
    <link rel="canonical" href="${currentPage.link}" />
    ```

1.  Create a system-region within the `<head>` tags of your Template:
    ```html
    <​system-region name="CANONICAL" />
    ```

1. Attach the Format to the `CANONICAL` region, at the Template, Configuration, or Page level.
1. Visit **Manage Site > Site Settings** and change **Link Rewriting** to **Absolute**.
1. Publish your pages.

> For a single page or a few pages, attach the Format at the page level and set that page's link rewriting under **Edit > Configure > Override the current Site's asset link rewriting behavior for this asset**.

## Adding an alternative canonical URL option

This example lets a page output a self-referencing canonical tag or point at another page instead.

1.  Create a system-region within the `<head>` tags of your Template:
    ```html
    <​system-region name="CANONICAL" />
    ```

1.  Create a [Shared Field](https://www.hannonhill.com/cascadecms/latest/articles/design-in-cascade/data-definitions/shared-fields.html) group with this XML:
    ```xml
    <​system-data-structure>
      <group identifier="canonical" label="Canonical Settings" restrict-to-groups="Administrators">
        <text field-id="eff3e93cc0a8003d49767a63e99b3d5d" help-text="Enable this if the current page is NOT the canonical page, e.g. it's a duplicate." identifier="canonical-alternate" label="Specify alternate canonical URL?" required="true" type="checkbox">
          <checkbox-item label="Yes" show-fields="canonical/canonical-url-type" value="yes"/>
        </text>
        <text field-id="eff3e93cc0a8003d49767a63e89422bd" identifier="canonical-url-type" label="Canonical URL Type" required="true" type="radiobutton">
          <radio-item label="Choose Page" show-fields="canonical/page" value="page"/>
          <radio-item label="Enter URL" show-fields="canonical/url" value="url"/>
        </text>
        <asset field-id="eff3e93cc0a8003d49767a63755ff381" help-text="Select the canonical page." identifier="page" label="Choose Page" type="page"/>
        <text default="https://" field-id="eff3e93cc0a8003d49767a638b0b971b" help-text="Enter the URL for the canonical page." identifier="url" label="Enter URL"/>
      </group>
    </​system-data-structure>
    ```

1. Add this Shared Field group to the top of one or more existing Data Definitions.
1.  Create a Velocity [Format](https://www.hannonhill.com/cascadecms/latest/articles/developing-in-cascade/script-formats/index.html) containing:
    ```velocity
    #set ($canonical = $currentPage.getStructuredDataNode("canonical"))
    #if (!$canonical.getChild("canonical-alternate").hasTextValue("yes"))
        ## use current page's URL
        #set ($href = $currentPage.link)
    #else
        ## use alternate canonical page URL
        #if ($canonical.getChild("canonical-url-type").hasTextValue("page"))
            #set ($href = $canonical.getChild("page").asset.link)
        #elseif ($canonical.getChild("canonical-url-type").hasTextValue("url"))
            #set ($href = $canonical.getChild("url").textValue)
        #end
    #end
    ## output the canonical tag
    <link href="${href}" rel="canonical" />
    ```

1. Attach this Format to the `CANONICAL` region.
1. Visit **Manage Site > Site Settings** and change **Link Rewriting** to **Absolute**.
1. Edit one or more pages, configure the canonical options, and publish.

> Only users in the `Administrators` group see these options, because of the `restrict-to-groups="Administrators"` attribute on the field group. Remove or adjust that attribute for your own groups.
