How to implement canonical code on homepage and product page?

How to implement canonical code on homepage and product page?

S02K
Tourist
8 0 1

Hi i have added this code on my website to display the actual canonical url and so it doesn't show page-2 and the canonical now links to my primary domain .nl instead of .be for the market belgium.

how do i now implement this code but also for the homepage and product page?

 

{% if template contains 'collection'%}
<link rel="canonical" href="{{ shop.url }}{{ collection.url }}" />
{% else %}
<link rel="canonical" href="{{ canonical_url }}" />
{% endif %}

Reply 1 (1)

NomtechSolution
Astronaut
1245 113 159

To implement the code you have provided for the homepage and product page, you can use the following steps:

  1. Open the template file for the homepage and product page.
  2. Locate the head section of the template file.
  3. Add the following code to the head section:

 

{% if template contains 'collection'%}
<link rel="canonical" href="{{ shop.url }}{{ collection.url }}" />
{% else %}
<link rel="canonical" href="{{ canonical_url }}" />
{% endif %}​