Remove unnecessary CSS in Drupal 6 & 7


add the function to the template.php file in your theme folder

 

Drupal 6

function mytheme_preprocess_page(&$vars){
 $css = $vars['css'];
//core modules
 unset($css['all']['module']['modules/node/node.css']);
//contrib
 unset($css['all']['module']['sites/all/modules/contrib/filefield/filefield.css']);
//custom
unset($css['all']['module']['sites/all/modules/custom/mymodule/mymodule.css']);
//theme css
unset($css['all']['theme']['sites/all/themes/mytheme/mytheme.css']);

 $vars['styles'] = drupal_get_css($css);
}

 

Drupal 7

 

function mymodule_css_alter(&$css) {
  $exclude = array(
 //core
   'modules/system/maintenance.css' => FALSE,
//contrib
    'sites/all/modules/contrib/module/module.css' => FALSE,
//custom
    'sites/all/modules/custom/module/module.css' => FALSE,
//theme
    'sites/all/themes/mytheme/mytheme.css' => FALSE,
  );
  $css = array_diff_key($css, $exclude);
}
Advertisements

Add custom css and js within a drupal module


As easy as to add this 2 lines:

drupal_add_js(drupal_get_path('module', 'mymodule') . '/myfile.js');
drupal_add_css(drupal_get_path('module', 'mymodule') . '/myfile.css');