Robin van der Vleuten

Remove Drupal stylesheets with hook_css_alter

When you start building Drupal themes, you quickly find a lot of default stylesheets in the page. If you want to remove some of them from your theme, implement hook_css_alter in template.php and unset the files you do not want.

Here is a small example:

php
<?php
/**
* Remove Drupal's core system stylesheets.
*/
function THEMENAME_css_alter(&$css)
{
$path_system = drupal_get_path('module', 'system');
$remove = array(
$path_system . '/system.base.css',
$path_system . '/system.menus.css',
$path_system . '/system.messages.css',
$path_system . '/system.theme.css',
);
// Remove stylesheets which match our remove array.
foreach ($css as $stylesheet => $options) {
if (in_array($stylesheet, $remove)) {
unset($css[$stylesheet]);
}
}
}

This removes the system module stylesheets before Drupal renders them. The same pattern works for any module stylesheet you want to remove.