Skip to content

Instantly share code, notes, and snippets.

@malcomio
Created January 22, 2014 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save malcomio/8556964 to your computer and use it in GitHub Desktop.
Save malcomio/8556964 to your computer and use it in GitHub Desktop.
Example of Drupal's hook_css_alter and hook_js_alter to remove unwanted core and contrib styles and scripts.
/**
* Implements hook_js_alter().
*
* Remove unwanted module JS.
*/
function mytheme_js_alter(&$javascript) {
$removal_list = array(
'google_cse' => array(
'/google_cse.js',
),
'menu_attach_block' => array(
'/menu_attach_block.js',
),
);
foreach ($removal_list as $module => $scripts) {
$module_path = drupal_get_path('module', $module) ;
foreach ($scripts as $script) {
$script_path = $module_path . $script;
if (isset($javascript[$script_path])) {
unset($javascript[$script_path]);
}
}
}
}
/**
* Implements hook_css_alter().
*
* Remove unwanted module CSS.
*/
function mytheme_css_alter(&$css) {
$removal_list = array(
'google_cse' => array(
'/google_cse.css',
),
'system' => array(
'/system.theme.css',
'/system.menus.css',
),
);
foreach ($removal_list as $module => $stylesheets) {
$module_path = drupal_get_path('module', $module) ;
foreach ($stylesheets as $stylesheet) {
$css_path = $module_path . $stylesheet;
if (isset($css[$css_path])) {
unset($css[$css_path]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment