Created
November 14, 2015 16:45
-
-
Save aklump/707b742f80ff9b207c89 to your computer and use it in GitHub Desktop.
Include a higher version of jQuery in your Drupal 7 theme using hook_js_alter in template.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Implements hook_js_alter(). | |
* | |
* Replace the system-provided jquery with our own higher version for the theme. | |
*/ | |
function my_theme_js_alter(&$javascript) { | |
// Go through and replace the jquery that is being provided by the system | |
// with out own higher version for the theme. We use an array | |
// here in case the jquery update module is/is not being used. | |
$original_jquery = array( | |
'misc/jquery.js', | |
); | |
// Sniff out jquery update jquery. | |
if (module_exists('jquery_update') && preg_match('/([^ ]+\/jquery_update\/[^ ]+?) /', implode(' ', array_keys($javascript)), $matches)) { | |
$original_jquery[] = $matches[1]; | |
} | |
$theme_js = array( | |
'data' => path_to_theme() . '/js/jquery-1.11.1.min.js', | |
'version' => '1.11.1', | |
); | |
foreach ($original_jquery as $key) { | |
if (isset($javascript[$key])) { | |
$javascript[$key] = $theme_js + $javascript[$key]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment