Adding canonical tag only to the homepage?

Topic summary

A user seeks to add a canonical tag exclusively to their homepage, pointing to a collections page that is being outranked due to cannibalization issues.

Technical Solution Provided:

  • Another user shares Liquid template code to be inserted near the top of theme.liquid
  • The code uses conditional logic ({% if template == 'index' %}) to target only the homepage
  • Implementation involves adding a <link rel="canonical"> tag that redirects to the preferred collections page

Status:
The solution appears complete, with the responder requesting the original poster mark the answer as helpful if it resolves the issue. The discussion remains open pending confirmation of successful implementation.

Summarized with AI on November 4. AI used: claude-sonnet-4-5-20250929.

Hello,

I was wondering if anyone can help. I need to change the homepage ONLY to refer to another page (a collections page) on my site, as the homepage is cannabalising the ranking and the collections page is the preferred page.

Is there any way of editing the html so just the canonical link on the homepage is updated (to direct to the product page?)

Many thanks!

Hey @chaweng2012 ,

This should be the code you need! Simply add it near the top of your theme.liquid file:

{% if template == 'index' %}
  
{% endif %}

If this resolves your issue, please consider marking the answer as helpful or accepted!