dynamic url in metafield type 'url'

Topic summary

A user needs to make a URL-type metafield dynamic to accommodate multiple countries and languages without manually translating each URL. The metafield currently contains static URLs like https://domain.com/pages/xyz but requires the https:// scheme, preventing the use of relative paths that would automatically inherit domain/country/language settings already configured in the theme.

Proposed solution:

  • Use the Metafields API with a small app or serverless function
  • Trigger on product creation/updates to dynamically construct URLs in the format https://{{domain}}/{{country}}/{{language}}/{{page_path}}
  • Retrieve country/language from request.locale or other context
  • Update the metafield programmatically with the generated URL

Status: The discussion remains open with one suggested approach but no confirmed implementation or alternative solutions yet explored.

Summarized with AI on November 1. AI used: claude-sonnet-4-5-20250929.

hi all, i have a ‘url’ metafield type in which i’d need to make ‘dynamic’

This metafield type requires a https:// scheme and the original value is like

https://domain.com/pages/xyz

I have 2 countries and languages and i’d prefer to not translate in the translate and adapt every single url but making this ‘dynamic’ like

https://domain.com/dynamicCountry/dynamicLanguage/pages/xyz

or even just

https://dynamicdomain%country&language/pages/xyz

the theme is already configured to recognize country and language so my problem here is just that the URL type metafield requires a https:// start and that isn’t allowing me to add only the /pages/xyz that would inheritate the domain/country/language as done in other page.

any thoughts? thanks in advance

1 Like

thanks! this seems a code for the theme, but i’d need to add this in a ‘url’ metafield placeholder - wdyt?

i think you can use Metafields API for that. You’ll need a small app or a serverless function to do this. The process would be:

  1. When a product (or whatever object the metafield is attached to) is created or updated, your app/function would trigger
  2. It would retrieve the country and language (likely from the request.locale if your app is theme-based or from other context if it’s external)
    It would construct the full URL: https://{{domain}}/{{country}}/{{language}}/{{page_path}} (where page_path comes from wherever you’re storing that part)
  3. It would then use the Metafields API to update the metafield with this dynamically generated URL

hope that helps!