Articles on: How to Install a Cookie Banner

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:


  1. Go to Shopify AdminOnline StoreThemes
  2. Click ActionsEdit code
  3. Open: layout/theme.liquid
  4. Insert your script before the closing </head> or </body> tag:
liquid
CopyEdit<!-- Example: Custom Script -->
<script>
console.log("Custom script loaded");
</script>
  1. 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:

  1. Go to Online StoreThemesCustomize
  2. Choose the page template
  3. Click Add block/sectionCustom Liquid
  4. 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 SettingsCheckout → 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

Was this article helpful?

Share your feedback

Cancel

Thank you!