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

13 Sep 2011

Joris Snoek
Digital Consultant
+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'];


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

Feedback, Questions about Theming?

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


Nóg meer
kennis nodig?

Check ons ons blog archief >