Share icon

Drupal provided the lots of hook to extents its functionality, using this we can prevent a js file to load on particular page using HOOK_JS_ALTER

If you want to load a js on every page except some page, below example will help you to achieving this.

function mymodule_js_alter(&$javascript) {
    $path = current_path();
    if($path == "my-path")
        unset($javascript['sites/all/themes/mytheme/js/theme.js']);
}

Reference of HOOK_JS_ALTER is here.

You can do

print_r($javascript)

to search your js and unset that according to location.

Thanks

 

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.