Removing Magento’s Miscellaneous HTML From a Specific Page(s)

Published by John on July 18, 2018 Under Magento

In Magento, one way to easily add header/footer scripts, like Facebook or Analytics tracking codes, is to use the configuration setting under Configuration->General->Design->HTML Head and Footer.

Both of those sections have a Miscellaneous Scripts setting, which you can add text into, which will get printed in the header and footer of the page respectively.

However, if for some reason you want to remove this on a certain page, it is not as easy as other layout changes, as you can not just use a remove or removeItem xml layout update, as you can with most other items in your template files. This is because of the way the header/footer miscelaneous scripts are added in the template files.

This will of course could vary based on your Magento Theme, but generally these scripts get added as follows:

The Header Scripts are typically added in base/default/template/page/html/head.phtml


getIncludes() ?>

The footer scripts are added in each of the template files, like base/default/template/page/1column.phtml, as follows:


getAbsoluteFooter() ?>

To remove it, you have a few options, but I think the easiest and cleanest is with a layout update.

So, if you were trying to remove the AbsoluteFooter Miscellaneous HTML from a specific page, you would first find what template that page uses and make a copy of it. For instance, if it was using 1column.phtml, you could copy it and call it 1column_no_footer.phtml and then remove the line with $this->getAbsoluteFooter() from the new file.

After that, you need to add a layout update, so that this page uses the new file. Of course, this will vary depending on the type of page(CMS, Product, Category, etc.) And, since there are a lot of ways to do this, I won’t go into great detail in this regard. However, for a CMS page, if you are comfortable creating or modifying a plugin, you could add this to the plugins etc/config.xml file:





page_info_landing_page

For removing the scripts from the header, you may be able to do it a little easier by copying head.phtml and then changing the layout.xml files to use the new file.

Other options would be to add some custom logic to the page(s) to check and not add the scripts as needed. You could also over-ride the page classes to either modify the getAbsoluteFooter function or a modified block type.


No Comments |

Add a Comment