Skip to content

Instantly share code, notes, and snippets.

@pixelwhip
Created April 18, 2012 05:43
Show Gist options
  • Save pixelwhip/2411333 to your computer and use it in GitHub Desktop.
Save pixelwhip/2411333 to your computer and use it in GitHub Desktop.
This is simple alter function I had to write while addressing an issue on the DrupalCon site. It led to this blog post. http://pixel-whip.com/blog/12/03/all-cool-kids-back-bus
<?php
/**
* Implements hook_js_alter()
*/
function shizzle_js_alter(&$javascript) {
// Collect the scripts we want in to remain in the header scope.
$header_scripts = array(
'sites/all/libraries/modernizr/modernizr.min.js',
);
// Change the default scope of all other scripts to footer.
// We assume if the script is scoped to header it was done so by default.
foreach ($javascript as $key => &$script) {
if ($script['scope'] == 'header' && !in_array($script['data'], $header_scripts)) {
$script['scope'] = 'footer';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment