1

I work on drupal 7, I added all js by info file, work well in whole site. But we want to remove or not load of a specific js in a specific content type page.

I try by template.php of following code

function mytheme_preprocess_page(&$vars) {
  if (isset($vars['node']->type) && !empty($vars['node']->type) && ($vars['node']->type == 'my_content_type')) {
    $js_path = drupal_get_path('theme', 'mytheme') . "/js/xyz.js";
      unset($vars[$js_path]);
  }
}

but load xyz.js. How to remove of this js file.

0

You can use hook_js_alter()

Perform necessary alterations to the JavaScript before it is presented on the page.

Parameters

$javascript: An array of all JavaScript being presented on the page.

Then you should be able to use menu_get_object() to load the node type and unset the js file in the $javascript array.

function MYTHEME_js_alter($javascript) {
  $node = menu_get_object();
  if ($node->type == 'node_type) {
    unset($javascript['path/to/script.js']);
  }
}

Note: I haven't tested this or checked syntax, let me know if it doesn't work and I will test.

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.