Adding canonical tag only to the homepage?

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!