jQuery update module is including this script.

<script type="text/javascript" src="/sites/all/modules/jquery_update/replace/jquery.min.js?6"></script>

I need this on every page, except a certain template file which I am using fancy box, and need a later version of jQuery.

I need to exclude jQuery update from putting the above script in the $scripts variable ONLY on page-media-photos.tpl.php. How can I achieve this?

5 Answers 5


Here are your options:

  • Use jQuery Multi, as mentioned in another answer. It can be configured to load the higher version of jQuery just on that page and just for the fancy box. It won't interfere with Drupal's jQuery or with jquery_update's jQuery.
  • In Drupal 7, you can use hook_js_alter(), which will let you swap out jquery_update's version with whatever you want.
  • In Drupal 6 with jQuery Update, it provides a hook that lets you alter the JS after it's done doing its thing. You can look at the jQuery Multi 6.x code to see how it uses this hook.
  • In Drupal 6 without jQuery Update, you can do this using a preprocess_page hook. The $scripts variable will be available there, and you can change it. This can get a bit tricky. You can also see how qmulti does this. jQuery Update also does this in a similar way.

Remember that swapping to a higher jQuery version can break some things in Drupal core and contrib, which is the problem jQuery Multi solves. So if you do this make sure you're not breaking anything. The benefit here is that you just load the jQuery you need, while with jQuery Multi you'll load both.

  • Note, hook_js_alter isn't available in D6 Commented Feb 1, 2013 at 23:31
  • 2
    Changed the answer to have D6 info as well.
    – goron
    Commented Feb 2, 2013 at 0:23
  • I agree with using jQuery multi if you want to run multiple versions of jQuery. I would only recommend jquery update if you want to run the newer version for your whole site. Also, in my experience, jquery update for jquery 1.7 & 1.8 is still to buggy to use in production.
    – rooby
    Commented Feb 2, 2013 at 1:34

There is a module jQuery multi. This module allows you to have multiple versions of jQuery run parallel on your drupal instance. It provides an alias for each instance which you can use for calling that version of jquery.


If you have troubles with jqueryupdate and views admin pages (for example) try to install Dev version of ctools and everything will be OK, just tested myself.


Please find this code may helpful, Place this code in your template.php

function MYTHEME_preprocess_page(&$vars) {
  $scripts = drupal_add_js();
  if (in_array('page-media-photos', $vars['template_files'])) {
  $vars['scripts'] = drupal_get_js('header', $scripts);

PATH_OF_JS_NEED_TO_REMOVE give the path of js for ex: sites/all/modules/og/og.js

  • function phptemplate_preprocess_page(&$vars) { $scripts = drupal_add_js(); if(in_array('page-media-photos',$vars['template_files'])) unset($scripts['all']['module']['/sites/all/modules/jquery_update/replace/jquery.min.js']); $vars['scripts'] = drupal_get_js('header', $scripts); } this did not seem to work
    – albo
    Commented Dec 27, 2012 at 18:18
  • I upvoted but it doesn't work
    – albo
    Commented Dec 28, 2012 at 19:46
  • I updated the code to indicate that you need to replace MYTHEME with your theme name instead of using "phptemplate". Also, I would not recommend using this type of approach to remove a librarye that other js depends on, like jQuery, because this doesn't take into account the order that js is loaded and you could end up with jquery is undefined errors if other jQuery plugins are loaded before a version of jQuery. Also, the way jQuery update works is more complex than just unsetting a js file.
    – rooby
    Commented Feb 2, 2013 at 2:15

Drupal 7

You can call jquery_update_jquery_replace() on specific page (e.g. it in hook_library_alter()) as demonstrated in here by drupalmoff:

 * Implements hook_module_implements_alter().
function your_module_module_implements_alter(&$implementations, $hook){
  if( $hook == 'library_alter' ){
    $group = $implementations ['your_module'];
    unset($implementations ['your_module']);
    $implementations ['your_module'] = $group;

 * Implements hook_library_alter().
function your_module_library_alter(&$javascript, $module) {
  if( $module === 'system' && current_path() == 'path/to/page' ) {
    // Make sure we inject either the minified or uncompressed version as desired.
    $min = variable_get('jquery_update_compression_type', 'min') == 'none' ? '' : '.min';
    $cdn = variable_get('jquery_update_jquery_cdn', 'none');
    $path = drupal_get_path('module', 'jquery_update');

    $version = '1.7';

    jquery_update_jquery_replace($javascript, $cdn, $path, $min, $version);

Drupal 6

My solution was to change JQUERY_UPDATE_REPLACE_PATH constant before jquery_update loads it:

 * Replace jQuery files on specified paths (fix for IE 6&7 - jQuery bug: bugs.jquery.com/ticket/6498)
// if (array_search($_GET['q'], array('my_page')) !== FALSE) {
if (arg(0) == 'node' && arg(1) == '123') {
  define('JQUERY_UPDATE_REPLACE_PATH', 'sites/all/libraries/jquery/1.5.2');

So it can be added either at very beginning of the .module file (which is loaded before jquery_update, or try in settings file.

  • Not to hijack your answer, but maybe you also want to add the D8 variatn of it? Commented Dec 23, 2016 at 13:59
  • I didn't play 8 too much, so I'm not sure what would be the solution for D8, sorry about it. Feel free to suggest edit, or post an answer. Or it may be worth to create another question for D8 specifically.
    – kenorb
    Commented Dec 23, 2016 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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