How to Remove Core and Module CSS from a Drupal 7 Theme
In the post on base themes that I wrote earlier this week, I pointed out that core adds a lot of CSS to your site that you may not want. If you find yourself overriding this CSS in your themes, you definitely have some bloat that you could trim down. You also run into this issue quite a bit with contributed modules. Views, Flexslider and Superfish are modules that typically add a lot of CSS I don't want.
So how to get rid of this potentially unwanted code? Below I've included a function that you can drop in your template.php file. Of course you need to replace YOUR_THEME in the function name with the name of your theme.
function YOUR_THEME_css_alter(&$css) { <br>// Remove Drupal core css <br>$exclude = array( <br>'modules/aggregator/aggregator.css' => FALSE, <br>'modules/block/block.css' => FALSE, <br>'modules/book/book.css' => FALSE, <br>'modules/comment/comment.css' => FALSE, <br>'modules/dblog/dblog.css' => FALSE, <br>'modules/field/theme/field.css' => FALSE, <br>'modules/file/file.css' => FALSE, <br>'modules/filter/filter.css' => FALSE, <br>'modules/forum/forum.css' => FALSE, <br>'modules/help/help.css' => FALSE, <br>'modules/menu/menu.css' => FALSE, <br>'modules/node/node.css' => FALSE, <br>'modules/openid/openid.css' => FALSE, <br>'modules/poll/poll.css' => FALSE, <br>'modules/profile/profile.css' => FALSE, <br>'modules/search/search.css' => FALSE, <br>'modules/statistics/statistics.css' => FALSE, <br>'modules/syslog/syslog.css' => FALSE, <br>'modules/system/admin.css' => FALSE, <br>'modules/system/maintenance.css' => FALSE, <br>'modules/system/system.css' => FALSE, <br>'modules/system/system.admin.css' => FALSE, <br>'modules/system/system.base.css' => FALSE, <br>'modules/system/system.maintenance.css' => FALSE, <br>'modules/system/system.messages.css' => FALSE, <br>'modules/system/system.menus.css' => FALSE, <br>'modules/system/system.theme.css' => FALSE, <br>'modules/taxonomy/taxonomy.css' => FALSE, <br>'modules/tracker/tracker.css' => FALSE, <br>'modules/update/update.css' => FALSE, <br>'modules/user/user.css' => FALSE, <br>'misc/vertical-tabs.css' => FALSE, <br>// Remove contrib module CSS <br>drupal_get_path('module', 'views') . '/css/views.css' => FALSE, ); <br>$css = array_diff_key($css, $exclude); <br>}
The Tao base theme uses something similar (I'm sure others do as well) and Mike Herchel showed off some of his resets in a recent presentation at Florida DrupalCamp. He has some other good stuff in there you might want to check out.
Play around with the code above and see if you can reduce the size of your pages - every little bit helps! If you have any comments on this post, you may politely leave them below.