Custom domain connection breaks Metaobject document and URL links in Shopify

Hey everyone, I’m having trouble with my Shopify store after connecting a custom domain. My product documents metafield, which uses a metaobject reference, isn’t working properly anymore.

The metaobject has both a file field and a URL field. I’ve set up a loop to display these documents, but the links aren’t clickable now. Here’s a simplified version of my code:

{% for document in product.metafields.custom.pdp_documents.value %}
  <div class="doc-row">
    <a href="{{ document.document_url }}">{{ document.title }}</a>
    <a href="{{ document.file | file_url }}" target="_blank">PDF</a>
  </div>
{% endfor %}

The weird thing is, when I check the dev tools, the hrefs seem to be correct. For example:

<a href="https://cdn.shopify.com/s/files/1/0598/5973/0494/files/Example_Document.pdf?v=1742598724">

I’ve tried using both the file_url filter and the document_url field, but nothing seems to work. Any ideas on what might be causing this and how to fix it? Thanks in advance for your help!

I encountered a similar issue when setting up my custom domain on Shopify. The problem likely stems from how Shopify handles asset URLs after domain changes. Here’s what worked for me:

First, double-check your domain settings in Shopify admin. Ensure your custom domain is properly configured and the SSL certificate is active.

Next, try using the ‘asset_url’ filter instead of ‘file_url’. It’s designed to handle custom domains better:

<a href="{{ document.file | asset_url }}" target="_blank">PDF</a>

If that doesn’t solve it, clear your theme cache by making a small change to your theme and saving it. This forces Shopify to regenerate asset URLs.

Lastly, if issues persist, contact Shopify support. They can check if there’s any misconfiguration on their end affecting your asset links.

Remember to test on different browsers and devices to ensure it’s not a localized issue. Good luck!

i had this problem too! try clearing ur browser cache first, sometimes that fixes weird url stuff. if not, check ur theme.liquid file. make sure the {{ content_for_header }} is there. that line is super important for loading shopify’s scripts properly. if nothing works, hit up shopify support, they’re usually pretty good at fixing these tricky domain issues.

Having dealt with custom domain issues in Shopify before, I can suggest a few additional troubleshooting steps. First, try using the ‘global’ object to reference your assets:

<a href="{{ 'Example_Document.pdf' | file_url | global_asset_url }}" target="_blank">PDF</a>

This method often resolves URL discrepancies after domain changes. If that doesn’t work, check your .htaccess file for any redirect rules that might be interfering with file access. Also, ensure your DNS settings are correctly pointing to Shopify’s servers.

If all else fails, consider temporarily reverting to the myshopify.com domain to isolate whether it’s a domain-specific issue. This can help narrow down the problem and provide clearer direction for a solution.