Drupal: How to Exclude Loading of CSS Styles System Tables
Drupal has embedded style files which define view of the main page elements such as menu type, tabs and tables. If you don’t need these elements, you can redefine them line by line in CSS file but this can be a little bored.
The simpler way is don’t download these files.
We are talking about these two files:
- /modules/system/defaults.css
- /modules/system/system.css – it is full of deeply embedded selectors and can cause a headache when adjusting your theme.
Before making changes
If you exclude these files, you should include another theme with style files for admin area.
After making changes
After adding the required functionality, you should open /admin/build/themes in browser to let Drupal view the function. Perhaps you will need to click Save button on the theme page…
Solutions
- Delete CSS file in template.php (Drupal 5, 6)
- Redefine system CSS-file in theme.info (Drupal 6 and higher)
- Change paths to system CSS-files
Delete CSS file in template.php
Drupal 6
Add the following to template.php of current theme:
function YourTheme_preprocess_page(&$vars)
{
$css = $vars[‘css’];
unset($css[‘all’][‘module’][‘modules/system/system.css’]);
unset($css[‘all’][‘module’][‘modules/system/defaults.css’]);
$vars[‘styles’] = drupal_get_css($css);
}
Drupal 5
Add the following to template.php of current theme:
function _phptemplate_variables($hook, $vars) {
$css = drupal_add_css();
unset($css[‘all’][‘module’][‘modules/system/system.css’]);
unset($css[‘all’][‘module’][‘modules/system/defaults.css’]);
$vars[‘styles’] = drupal_get_css($css);
return $vars;
}
If “_phptemplate_variables” function already exists in template.php then you should insert this code into the existing function.
Delete CSS-files of modules
here is the example of excluding CSS-file of Help module:
function _phptemplate_variables($hook, $vars) {
$css = drupal_add_css();
$rm = drupal_get_path(‘module’,’help’).’/help.css';
unset($css[‘all’][‘module’][$rm]);
$vars[‘styles’] = drupal_get_css($css);
return $vars;
}
drupal_get_path function is used to find a path to a module because it can be located in different places.
Redefine system CSS-file in theme.info
This alternative is for Drupal 6 or higher.
Please redefine the default system style file in .info-file of your theme. For example, to redefine the default system styles for menu, you should add:
stylesheets[all][] = system-menus.css
Change paths to system CSS-files
Another way to solve the problem – do not use the default style files but copy these files, modify them and change a path to the file.
- Copy defaults.css from modules/system to a folder of a current theme
- Make the required changes in new defaults.css within the folder of a current theme
- Change a path to css-file in page.tpl.php of a current theme. This means to change a path to defaults.css file in $styles variable with the help of preg_replace PHP function.
For example, if files of a new theme (including just copied defaults.css) are in sites/all/themes/drupal-test-theme folder, you should replace this code in page.tpl.php :
print $styles
with this one:
$styles = preg_replace(‘/modules\/system\/defaults.css/’, ‘sites/all/themes/drupal-test-theme/defaults.css’, $styles);
print $styles;