I have this snippet of code in my template.php file which in theory should place the scripts in the $header_scripts
array into the <head>
of the page, and place the others in the 'footer scope' unless they define their own scope as the header.
It is placing the scripts in the footer, but doesn't seem to place my modernizr anywhere. I've checked the path and that is correct so it must be something else, but I'm out of my Drupal depth.
function lightweight_js_alter(&$javascript) {
// Collect the scripts we want in to remain in the header scope.
$header_scripts = array(
'sites/all/libraries/modernizr/modernizr.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';
}
}
}