Skip to main content

url

A URL object from a url setting or a url metafield.

When URLs are saved as references to Shopify resources, they return dedicated object drops.

When the url object is referenced directly in a theme file, the url string is returned.

Properties

Anchor to
object

The resource that the URL points to.

The object can be one of the following:

For any other type, or if the resource no longer exists, nil is returned. A path that's entered as text, such as /products/walrus-socks, is a relative_link, so its object is nil even if the path matches a resource.

Anchor to
type
string from a set of values

The type of the URL.

The type depends on how the URL was set:

  • A resource that's selected in the theme editor returns the type of that resource, such as product_link or catalog_link.
  • A path that's entered as text, such as /products/walrus-socks, returns relative_link, even if the path matches a resource. The only exception is /, which returns home_link.
  • A path from a dynamic source, such as {{ page.url }}, also returns relative_link.
  • An absolute URL returns external_link, even if it points to the store.
Possible valuesDescription
anchorThe URL points to an anchor on the current page, such as #faq.
article_linkThe URL points to an article.
blog_linkThe URL points to a blog.
catalog_linkThe URL points to the catalog page (/collections/all).
collection_linkThe URL points to a collection.
collections_linkThe URL points to the collection list page (/collections).
external_linkThe URL is an absolute URL that starts with http, https, mailto, or tel.
home_linkThe URL is the home page path (/).
metaobject_linkThe URL points to a metaobject page.
page_linkThe URL points to a page.
policy_linkThe URL points to a policy page.
product_linkThe URL points to a product page.
relative_linkThe URL is a path that was entered as text or comes from a dynamic source, such as /pages/about.

The URL.

The URL string to be used as the href in links. This is the same value that's returned when the url object is referenced directly.

URLs that point to store resources, the home page, and the collection pages include the path prefix of the current locale, such as /fr/collections/spring. Relative paths and anchors are returned exactly as they were entered.

Was this section helpful?