Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How can I add Javascript to a “SINGLE” Product Page
 
ncotrona
Sr. Member
 
Total Posts:  161
Joined:  2009-05-15
 

I need to add a javascript file to a specific product.  Only one product in my catalog....  The code needs to be added just inside the opening <head>; tag.  Does anyone know how I might be able to add the code to an individual product page ONLY.  I do not want to add this code to any other pages on my site… .Please note, this is not a CMS page or Category Page....  This is a product page.....

The product page I want to add the code to is
http://www.sumppumpsusa.com/sumpro-model-75-sump-pump-battery-backup-system-batteries-included.html

Any assistance is much appreciated…

 
Magento Community Magento Community
Magento Community
Magento Community
 
Siggi_Schmitz
Enthusiast
 
Avatar
Total Posts:  811
Joined:  2011-07-03
 

Hmmmm, there are a few options.

You can edit the file “app/design/frontend/base/default/template/page/html/head.phtml”, there you can check if the actually site is a product site and the correct product is load with:

if (Mage::registry('current_product')) {
     
if (Mage::registry('current_product')->getId() == $productId// replace $productId with the id you search
          //insert your js script
     
}
}

of course, put the template file in your own theme!

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

Hello
You can try to add this next section in your catalog.xml layout file

<PRODUCT_439><!-- 439 is the id of your product -->
    <
reference name="head">
        <
action method="addJs"><js>path/to/js.js</js></action><!-- relative to the 'js' folder -->
    </
reference>
</
PRODUCT_439>

Clear the cache and refresh.
Marius.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top