How to Add Custom Javascript to Your Shopify Theme
Do you want to add a JavaScript in your Shopify pages? Sometimes you may need to add a JavaScript code to the entire website or into specific pages. In this article, we will show you how to easily add JavaScript in Shopify pages.
- From your Shopify admin, go to Online Store > Themes.
- Find the theme you want to edit, and then click Actions > Edit code.
- Under Assets, click on to Add a new asset
- A dialog popup will appear. Switch to Create a blank file tab. You must to fill the name for new file (eg: hura-custom) and select .js.liquid.
- Click Add asset. This is the custom JS file you’ll be editing to add your custom JS.
- Under Layout, select theme.liquid.
- Scroll down the page until you find the closing body tag (</body>).
- Paste the below code just before the tag.1{{ 'hura-custom.js' | asset_url | script_tag }}
- Click Save and you are done.
Now if you want to add any custom Javascript code to your Shopify page, just open the generated JS file (hura-custom.js.liquid) to edit.
Happy coding!