How to make unwanted Drupal CSS disappear!

<?php
// get all the current css information into an array
$css = drupal_add_css();

// copy stuff you want to keep from these sites/default/files into your theme's style.css
// or maybe make a separate file for that and @import it into that file

// now we can ditch unwanted core css sites/default/files from the array and they won't be included
unset($css['all']['module']['modules/user/user.css']);
unset(
$css['all']['module']['modules/node/node.css']);

// and now, removing the css sites/default/files of some contributed modules
// I'm putting them into an array to save space and code repetition
$rm[] = drupal_get_path('module','content').'/content.css';
$rm[] = drupal_get_path('module','devel').'/devel.css';
$rm[] = drupal_get_path('module','gotcha').'/gotcha.css';

// now we can remove the contribs from the array
foreach ($rm as $key => $value) {
  unset(
$css['all']['module'][$value]);
}

// now place the remaining css sites/default/files back into the template variable for rendering
$vars['styles'] = drupal_get_css($css);
?>

Blog Tags: DrupalThemesCSSWeb Design

Comments

I was trying to kill the system generated CSS and this functions was very use full.

Further if we can customize to override the selected css with the css we want (file) that would be even better

Thanks! I didn't know the drupal_add_css method returned the state of all css if called with no params. It also seems like you could use this to remove core css within a module in order to keep css aggregation working

Add new comment