how do I add javascript code to an individual page

katiedps
New Member
6 0 0

Hi

I want to add javascript code to one page only in my shopify store

is it possible to do this?

thanks katie

0 Likes
Elle
Shopify Staff
Shopify Staff
1016 74 163

Hi, Katie!

Elle here from Shopify's Social Care team. 

In order to add Javascript to a single page, you'll need to create a new page template under Online store > Themes > Actions > Edit Code. 

Here's how it will look: 

Once you've created the new template, look for the following snippet of code:

<div class="rte">

Paste your Javascript code above this line of code. Make sure to wrap it with <script> </script> tags.

Once you have this done, you can assign the new template to the page you'd like to apply it to here:

Hope this is helpful! 

Elle | Social Care @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

drtyrell
New Member
8 0 0

Do we have to copy the quick-add.js from the script/global/quick-add.js location to the assets folder?

0 Likes
cyn554
New Member
2 0 0

I also want to add javascript code to an individual page and I tried to follow the instructions above but when I create the new page template, I don't see the piece of code referenced above:  

<div class="rte">

 I see a different piece of code that looks like this:   { % section "page" % }

 

Can you please advise?

 

0 Likes

To add JavaScript to an individual or group of Shopify pages:

  1. Go to your Shopify Admin and go to Online Store
  2. Click Actions > Edit Code
  3. Under your Templates folder, select Add a new template
  4. Choose the type of page you want the JavaScript to be added to. I will choose page as an example.
  5. Click Create template
  6. At the bottom of this file, include your JavaScript. Be sure to wrap it in <script></script> tags. I added a simple alert.
  7. Go to Page and Add or edit a page.
  8. In the page editor on the right-hand side, select the new template you just created.
  9. Test your page out! The JavaScript you wrote should be working.
  10. If you want this to apply to multiple pages, change the templates of the other pages you want the JavaScript to run on.

If you need additional help, check out the step-by-step screenshots on my blog post here.

0 Likes