Created
January 22, 2014 11:05
-
-
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.
This file contains 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(). | |
* | |
* 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