cancel
Showing results for 
Search instead for 
Did you mean: 

How to add specific JS/CSS Code only to certain CMS page?

How to add specific JS/CSS Code only to certain CMS page?

In Magento it is possible to write <script></script> and <style></style> tags and use JS/CSS directly in CMS pages, which is the easiest and fastest way to add code to only a certain CMS page.

 

There is also a more complicated way described here, you can add JS/CSS through the filesystem, by using layout updates.

 

Our Agency says that the first way is very dirty and we should stop doing it like this and instead use the second way because they want every change to appear in git.

Are both ways ok, should I listen to the Agency?

1 REPLY 1

Re: How to add specific JS/CSS Code only to certain CMS page?

To add the css or js for particular CMS page, you can do this from admin.

1. Open that CMS Page.
2. Open the "Design" tab from sidebar.
3. There are you get options like "Layout Update XML"
4. Into this field you are able to add Css and Js file for specific CMS Page only.

<reference name="head">
  <action method="addItem"><type>skin_js</type><name>js/your_foldername/your_js_name.js</name></action> 
  <action method="addItem"><type>skin_css</type><name>css/your_foldername/your_css_name.css</name><params/></action>
</reference>
Was my answer helpful? You can Click Kudos/Accept As Solution.
200+ professional extensions for M1 & M2 with free lifetime updates!