Magento: Add Javascript to Home Page Only (Or Any CMS Page)

Magento Icon

Have you ever needed to include a javascript file to the home page only to run that sweet slideshow you have displayed (or any other reason)? Fortunately, you don’t have to modify any of the layout files, or add it to your head.phtml file. CMS pages in Magento allow you to modify the layout XML specific to that page. So, all you need to do is open up the CMS page in Magento that you want to add the javascript to, click on the “Custom Design” tab on the left, and in the “Layout Update XML” field add the following:

<reference name="head">
  <action method="addItem">

Or, if you want to just put the javascript in the /js/ directory of your app, you can change the “skin_js” to just “js”.

This entry was posted in Uncategorized. Bookmark the permalink.

12 Responses to Magento: Add Javascript to Home Page Only (Or Any CMS Page)

  1. benabee says:

    Is possible to add an external JS ? I’m trying to add a Skype button . I must include this js :

    I can’t fin a solution that works ..

  2. shilpi says:

    Really very nice stuff & useful for me. Thanks :)

  3. Eduardo says:

    In 1.7 i use name insted of script like that:


  4. Mahmood says:


    I tried your suggestion and unforunately I am unable to link the file.
    In Custom layout of a particular page, I tried adding


    my js file is placed in skin/frontend/base/my_theme/js. I would greatly appreciate if you can email ( me a detail instruction. I am new Magento user. Thanks

  5. Free Quiz says:

    how about adding css files
    replace skin_js with skin_css ?


  6. nick scott says:

    sorry my previous post got mangled a little. What happens when you a have an external link to your .js?

  7. nick scott says:

    How does this work when you have something like i.e the .js file is on another server. Thanks.

  8. pc game says:

    Thank for information :)

  9. jef says:

    best magento source I have found yet.

  10. Eric says:

    Exactly what I needed! Thanks a bunch!

  11. neha says:

    Thanx a lot…its really useful tip………….

  12. That’s a really useful tip. Thanks.