Hide js script on one page

A script is being added globally to all CMS pages via the site footer html. Is there a way that we can hide that script on one particular page? Not finding anything so far that has been helpful.

Any suggestions would be greatly appreciated.

Thanks,

Terry McMillan

Hi @tmcmillan99,

The best way to do this owuld be to create a new template that includes a different version of the footer html without the script. Then you can switch the page to use the new template.

Best,

@JBeatty

Hey Joshua-

Thanks for the reply and the suggestion. Unfortunately, I don’t believe a new template is not going to solve the issue. The script is not being added via the footer in the template. It’s being added globally through the portal settings under Website - Pages - Templates tab. Unless I am missing something?

Thanks,

Terry

Hi @tmcmillan99,

Ah I see waht you mean. Then I would suggest doing something along the lines of what @albertsg suggested. Though I am unsure if within that template section you can use HUBL, so you’ll need to test that. If you can’t the same principle still applies, by writing some simple javascript to look at window.location.href, and then deciding whether or not to inject the script.

Best,

Hi @tmcmillan99, while creating a new template without the script and assigning it to the desired page is a good solution, you also have the following options if you want to keep everything in the same template:

- Add the script into an {% unless %} statement that will check the page URL (using for example {{request.path}}, more at: HubL variables - HubSpot docs )
- Add a boolean module to your template so content editors can enable/disable this script while editing the page. Then in the code you just need to check this module and show/hide the script as per its value.

@JBeatty @albertsg

Thanks for the suggestions. I will explore the option of checking the path before injecting the script either with hubl or js.

Thanks,

Terry