A developer encountered an issue where Liquid code for generating canonical URLs was returning an empty string. The goal was to strip query parameters (like ?page=srnqqdjnmld) from collection URLs to display clean canonical URLs.
Root Cause:
The problem was caused by extra curly braces {{ }} in the variable assignment: {% assign canonicalUrl = {{ canonical_url }} %}. This syntax error prevented proper variable assignment.
Solution:
Removing the extra braces fixes the issue: {% assign canonicalUrl = canonical_url %}
Additional Context:
One responder noted that Shopify’s canonical_url variable already returns the page’s default URL with parameters removed, making additional manipulation unnecessary.
A follow-up question raised whether the conditional check should use == instead of != for the page parameter comparison, though this wasn’t definitively resolved.
Status: Issue resolved through syntax correction.
Summarized with AI on November 15.
AI used: claude-sonnet-4-5-20250929.