Removing not-needed CSS files from contrib and core modules in Drupal

13 Sep 2011

Joris Snoek - Business Dev
+31 (0)20 - 261 14 99

Ever wanted to get rid of those CSS files you don't really need for your specific Drupal websystem. And can mess up your ow so beautiful custom HTML/CSS?

Contrib and core modules can really come in handy if used for the right purposes for the right functionallity. Here at Lucius we do a really really good screening before using a contrib module. Screening on code quality, security, activity, maintainers and so on.. With also in mind: the scalability of your Drupal websystem and the future of Drupal itself: will the module likely be continued in Drupal 7, for example.

Some of those contrib (and core) can generate a CSS file that will be included in your HTML head.
Here a little piece of code that will 'unset' these. Off course you have to alter the code to your system specific: only unset the ones you want to unset.

The allmighty theming code

Insert this snippet in your theme's template.php

/**
* Override or insert PHPTemplate variables into the templates.
*/
function YOURTHEME_preprocess_page(&$vars){

  // Unset insignificant stylesheets.
  $css = $vars['css'];

  unset($css['all']['module']['modules/node/node.css']);
  unset($css['all']['module']['modules/system/defaults.css']);
  unset($css['all']['module']['modules/system/system-menus.css']);
  unset($css['all']['module']['modules/user/user.css']);
  unset($css['all']['module']['sites/all/modules/contribs/cck/theme/content-module.css']);
  unset($css['all']['module']['sites/all/modules/contribs/filefield/filefield.css']);
  unset($css['all']['module']['sites/all/modules/contribs/cck/modules/fieldgroup/fieldgroup.css']);
  unset($css['all']['module']['sites/all/modules/contribs/date/date.css']);

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

Feedback, Questions about Theming?

Please hit me on Twitter for all your feedback, and any other issue!

Comments

Nóg meer
kennis nodig?

Check ons ons blog archief >