How to add script to Shopify
1. Add Script to All Pages (Theme Code)
Use this method if you're embedding JS across the whole store (e.g., Google Analytics, custom events):
Steps:
- Go to Shopify Admin → Online Store → Themes
- Click Actions → Edit code
- Open:
layout/theme.liquid
- Insert your script before the closing
</head>
or</body>
tag:
liquid
CopyEdit<!-- Example: Custom Script -->
<script>
console.log("Custom script loaded");
</script>
- Click Save
2. Add Script to Specific Page (e.g., Product Page Only)
Open the file you want (e.g., product.liquid
, product-template.liquid
, or main-product.liquid
) and add your script there.
liquid
CopyEdit{% if template == 'product' %}
<script>
// Custom product page logic
</script>
{% endif %}
3. Use Shopify’s Customizer (Settings > Custom Liquid)
Shopify themes (2.0+) may allow Custom Liquid blocks:
- Go to Online Store → Themes → Customize
- Choose the page template
- Click Add block/section → Custom Liquid
- Insert your script like this:
liquid
CopyEdit<script>
console.log("This script runs on the homepage only.");
</script>
4. Add Script via Shopify Admin (Checkout)
If you're on Shopify Plus, you can customize the checkout:
- Go to Settings → Checkout → scroll to Order Status Page
- Paste your script under Additional Scripts
5. Use Shopify Apps
For things like Facebook Pixel, Google Analytics, etc., Shopify recommends installing their official apps or integrating via Shopify > Settings > Customer Events.
Updated on: 21/07/2025
Thank you!