hreflang issue on collection page

Topic summary

Hreflang tags on product pages do not match the URL path used when navigating from a collection. When a product is clicked within a collection, the visible URL includes the collection segment (e.g., /collections/sportsocken/products/ava-socken-pink), but the generated hreflang points to the canonical product URL (e.g., /products/ava-socken-pink), triggering hreflang validator errors.

Ask: Generate hreflang URLs dynamically to include the collection path so alternates mirror the collection-based product URL. The requester notes Shopify auto-generates product URLs without the collection segment and seeks a way to override or conditionally include the collection handle in hreflang.

Key terms: hreflang (HTML tag indicating language/region-specific alternate URLs), collection (Shopify grouping of products), canonical product URL (Shopify’s default /products/handle path).

Status: No confirmed solution provided. The discussion remains open, with the requester looking for implementation guidance to dynamically construct hreflang entries that reflect the collection context.

Summarized with AI on December 18. AI used: gpt-5.

I have an issue on the Hreflang tag. The problem is there is a collection page. and in the collection page, there is some products. So when I click a product it generates like below.

collections/sportsocken/products/ava-socken-pink

in Hreflang , it generate like below.

products/ava-socken-pink

so Hreflang test giving me error. how to fix this. so how to generate a valid hreflang?

Hi thanks for your reply.

I need this generated dynamically. Currently, Shopify automatically generates URLs like https://domain/products/ava-socken-pink but how to generate the URL dynamically like https://domain/collections/sportsocken/products/ava-socken-pink