I want to link the logo of my site (in my main header) to the homepage of my store. I could do so by linking to the absolute URL (e.g., https://www.example.com), but that doesn’t work when I’m testing on a development server that isn’t hooked up to my domain name.
I know that I can link to pages using <a href="{{ pages.example.url }}">
, where example
is the page I want to link to. But using <a href="{{ pages.index.url }}">
doesn’t seem to work — I’m assuming because index
is not actually considered a page.
Is there an easy way to link to my store’s homepage using a liquid tag?
3
Answers
I figured it out, for those curious: Just link to
"/"
. So, a link to the homepage of your site should appear as follows in your header.liquid file:You can use
{{ shop.url }}
as listed on this variable cheat sheet and in the Shopify developer reference.You also have the option of using the secure version
{{ shop.secure_url }}
I also found in a quick test that it will also return the preview URL when previewing an unpublished page e.g.
k29ijan0ye0r5g7k-51325174.shopifypreview.com
<a href="/">Link</a>
This doesn’t work for multilanguage stores.I think better solution is:
{{ routes.root_url }}