1

I have this MailChimp embed script (for a subscribe popup) that I want to use on all the pages in my Magento 1 installation, except for one CMS page (because it already contains an embed script for a subscribe popup).

Normally, I would add this script to the 'Miscellaneous Scripts' option in System > Configuration > Design. How can I solve this the right way?

2

You could add the script using xml. Then you could use the layout update xml tab within the admin for the CMS page you want to remove script from the page. e.g:

1. Add JS to all pages:

<?xml version="1.0"?>
  <layout version="0.1.0">
    <default>
      <reference name="head">
        <action  method="addItem"><type>skin_js</type><name>js/popup.js</name></action>
    </reference>
  </default>
</layout>

This could be added to your local.xml file within your theme and will apply to all pages then due to being within default node.

2. Remove JS from a CMS Page:

<reference name="head">
  <action method="removeItem"><type>skin_js</type><name>js/popup.js</name>
  </action>
</reference>

This can be added to that CMS pages layout update xml field within admin so is just applied to that page. Navigate to CMS -> Pages -> Design. Then paste above into the layout update xml field.

3. Add JS file to filesystem.

The popup.js file should then be placed within the themes's JS folder:

skin/frontend/theme/default/js/popup.js
  • Very nice answer! I had multiple javascript files, so I used your method, but instead of using js files, I used a static block. Still, good answer! – Maarten Wolfsen Nov 20 '17 at 13:22
  • Awesome thanks! – harri Nov 20 '17 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.