How to add Custom Javascript to Shopify?

If you started Shopify Theme Development or Customization then you may be curious to know How to Add Custom Javascript to Shopify Theme in the Right way. Sometimes you may need to add a JavaScript code to the entire website or into specific pages In this post, I am going to show you How to Add Custom Javascript to Your Shopify Theme?

So Let’s Get Started:

y

1. From your Shopify admin, go to Online Store > Themes.

2. Find the theme you want to edit, and then click Actions > Edit code.

3. In the Assets directory, click on Add a new asset.

4. A dialog popup will appear. Switch to Create a blank file tab. You must fill in the name for the new file (eg: custom) and select .js.liquid.

5. Click Add asset. This is the custom JS file you’ll be editing to add your custom.js file.

6. In the Layout directory, select theme.liquid.

7. Scroll down the page until you find the closing body tag (</body>) and paste the below code just before the tag.

{{ 'custom.js' | asset_url | script_tag }}

8. Click Save and if you want to add any custom Javascript code to your Shopify page, just open the JS file and edit.

If you need any help please leave your queries in the comment box.Hexpound­­­­softtechsolution