<p>You should be able to use <code>{{ entry.categoryFieldHandle[0].slug }}</code>. The <code>[0]</code> simply grabs the first category in the field. </p>

<p>You will need to make sure there is always at least one category allocated to an entry or you'll get an error.</p>

CC BY-SA 3.0
2017-01-03T11:47:41.843Z
2017-01-03T11:47:41.843Z
Luke Pearce
<p>I'm building a shop using Craft Commerce where a single product can be assigned to multiple categories. The url structure I'm using for the product detail page is: <a href="http://domain.com/category/product-url" rel="nofollow noreferrer">http://domain.com/category/product-url</a></p>

<p>In an effort to avoid being penalised for duplicate content I would like to set the canonical URL for my product detail page by always pulling the first category as the canonical URL in the meta. I've tried a few things but keep getting stuck - any tips ? </p>

<categories><plugin-craftcommerce>
Canonical url for product with multiple categories
# Canonical url for product with multiple categories

(Asked by: username_0 on 2017-01-03)

I'm building a shop using Craft Commerce where a single product can be assigned to multiple categories. The url structure I'm using for the product detail page is: <http://domain.com/category/product-url>

In an effort to avoid being penalised for duplicate content I would like to set the canonical URL for my product detail page by always pulling the first category as the canonical URL in the meta. I've tried a few things but keep getting stuck - any tips ?

**Tags:** categories, plugin-craftcommerce


---

## 1 answers

### Answer by username_1 on 2017-01-03. Score: 2 | Accepted answer

You should be able to use `{{ entry.categoryFieldHandle[0].slug }}`. The `[0]` simply grabs the first category in the field.

You will need to make sure there is always at least one category allocated to an entry or you'll get an error.


---

