2

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 ?

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.