Before you start
- A Shopify plan with the Online Store and themes. Basic and higher plans include the theme editor. The low-cost Starter plan has no editable theme, so this method does not apply there.
- An Online Store 2.0 theme. Shopify's free themes, including Horizon and Dawn, have a Custom Liquid section. Most paid themes do too, sometimes under a slightly different name such as "Custom code"; check your theme's documentation if you can't find it.
- A free ExpressMaps API key. Sign up (no card), then copy a key from Console → Keys.
- Your location as longitude and latitude. Our map embed generator makes this easy: drag and zoom to your address, double-click to drop the marker, and it puts the numbers into the code.
Step 1: Copy the map code
Replace YOUR_API_KEY with your key and the two sets of numbers with your location. The order is longitude, then latitude: [-0.1276, 51.5072] is London.
<link rel="stylesheet" href="https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl.css">
<script src="https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl.js"></script>
<div id="map" style="width:100%;height:400px;"></div>
<script>
var map = new maplibregl.Map({
container: "map",
style: "https://tiles.expressmaps.com/styles/standard.json?key=YOUR_API_KEY",
center: [-0.1276, 51.5072],
zoom: 13
});
map.addControl(new maplibregl.NavigationControl());
new maplibregl.Marker()
.setLngLat([-0.1276, 51.5072])
.setPopup(new maplibregl.Popup().setText("Our shop"))
.addTo(map);
</script>
The embed generator writes this same code (the HTML (MapLibre) tab) with your style, position, popup text and key filled in. It is plain HTML, which a Custom Liquid section accepts as it is.
Step 2: Add the map to your Contact page
- In your Shopify admin go to Online Store → Themes and click Customize on your current theme.
- In the page selector at the top of the editor (it shows Home page at first), choose Pages, then the Contact template.
- In the left sidebar, click Add section where you want the map, for example below the contact form, and choose Custom Liquid.
- Click the new section and paste the code into the Liquid code box.
- The preview updates; click Save.
The map appears on every page that uses the Contact template, which is usually just /pages/contact.
Or on another page (for example "Visit us")
Adding the section to the default page template would put the map on every ordinary page, so give the map page its own template:
- In the theme editor's page selector choose Pages, then Create template. Name it, for example
map, base it on Default page, and click Create template.
- Add a Custom Liquid section to it with the map code, as above, and click Save.
- In the admin go to Online Store → Pages, open your page, and in the Theme template box on the right choose map. Save.
The same Custom Liquid section also works on the home page, or in the footer on themes that let you add sections there.
Comfortable editing theme code?
You can paste the snippet into a theme file instead (Online Store → Themes → … → Edit code), but the Custom Liquid section is the safer choice: it needs no file edits, you can move or delete it in the editor. Duplicate your theme as a backup before editing code.
Step 3: Restrict your key to your domain
Anyone can read your key in the page source; that is normal for web maps. The domain restriction stops other websites from using it.
- Go to Console → Keys and open your key.
- Under Key Restrictions, type a domain without
https:// or a path and click Add Restriction.
- Add each address your store is viewed on as its own entry:
yourstore.com, www.yourstore.com, and your your-store.myshopify.com address, which the theme editor preview and some links use.
- Click Save Changes. It applies to new requests shortly after saving.
Once a key has restrictions, pages on any domain not in the list get a "403" error instead of the map.
Troubleshooting
- An empty grey or white box. Check the key: is
YOUR_API_KEY replaced, and is the exact domain in your address bar (with or without www., or myshopify.com) on the key's restriction list?
- Works on the live store but not in the theme editor (or the reverse). Add your
myshopify.com address and your own domain to the key.
- Nothing at all, no box. The map has no height. Keep
height:400px in the snippet.
- The map is in the ocean. Longitude and latitude are swapped. MapLibre wants
[longitude, latitude].
- There is no Custom Liquid option. Older (vintage) themes have no sections on pages. Switch to a free Online Store 2.0 theme, or ask your theme developer where custom HTML can go.
- The map shows on every page. The section went into the default page template. Remove it there and use a separate template as described above.
- Visitors cannot see the store at all. A store with password protection shows only the password page to the public; the map appears once the store is open.
Things to know
- Is it really free? Yes. The free plan includes 100,000 map loads a month, commercial use allowed. One map load is one page view showing the map; panning and zooming are free.
- Do I need a cookie banner for the map? Not for the map itself: the map sets no cookies and does not track your customers. Shopify and other apps on your store may still need consent.
- Will it slow down my product pages? No. The map code only loads on the pages where you add the section.
- Can I change the style? Replace
standard in the style address with basic, enhanced, darklands, greyscale, navigator, subtle, autobahn, lithium or mulberry. See them all on the styles page.
- Can I show a second address, such as a pickup point? Yes, for a few locations copy the four
new maplibregl.Marker() lines and change the numbers and popup text.
- Page scrolling gets stuck on the map on phones. Add
cooperativeGestures: true, after zoom: 13, so visitors move the map with two fingers and scroll the page with one.
- Do I have to keep the "© OpenStreetMap" credit? Yes, the data licence requires it; the map adds it automatically.
- Is there a shorter version? Our expressmaps helper takes a little less code. After the two MapLibre lines add
<link rel="stylesheet" href="https://unpkg.com/expressmaps@1.0.1/dist/expressmaps.css"> and <script src="https://unpkg.com/expressmaps@1.0.1/dist/expressmaps.umd.js"></script>, then:
<div id="map" style="width:100%;height:400px;"></div>
<script>
expressmaps.createMap({ container: "map", key: "YOUR_API_KEY", center: [-0.1276, 51.5072], zoom: 13, marker: { popup: "Our shop" } });
</script>
Get a free API key Open the embed generator