How to get rid of Drupal CSS stylesheets?

回眸只為那壹抹淺笑 提交于 2019-12-05 02:09:14
<?php
/**
 * Helper function to allow easy CSS excludes + includes
 */
function _phptemplate_get_css($exclude = array(), $include = array()){
$css = drupal_add_css();
foreach ($css['all']['module'] as $k => $path) {
   $file = substr($k, strrpos($k, '/') + 1);
   if (in_array($file, $exclude)){
     unset($css['all']['module'][$k]);
   }
}
foreach ($include as $file){
   $css['all']['theme'][path_to_theme() .'/'. $file] = true;
}
return drupal_get_css($css);
?>

Read more at drupal.org.

Update:
The proper place to put this function, is in the template.php file of your theme. Actually in your case you need to pass an array of css filenames which you want to exclude.
The call to drupal_add_css() with no arguments passed, will provide $css with an array of CSS files which are going to be attached to your theme. So this is the right time to get in!

As you see, In the first foreach loop we simply seek the $css array for filenames which are existed in the passed $exclude array, for style deletion. And we do the same job in the second loop for style insertion. And at the end of this, we return a themed representation of all styles that should be attached to the theme making use of drupal_get_css() function. (maybe nothing in your case)

Well, Where to call this function? You can call this helper function in _phptemplate_variables() for D5 or YOUR_THEME_preprocess() for D6. As we see this in action for D6 (untested):

function YOUR_THEME_preprocess(&$vars, $hook){
    // Stylesheet filenames to be excluded.
    $css_exclude_list = array(
        'lightbox.css',
        'lightbox_lite.css',
    );

    // Making use of previously defined helper function.
    $vars['styles'] = _phptemplate_get_css($css_exclude_list);
}

I'm sure you know how to exclude 'em all ;)

If you define CSS and/or JavaScript files in your theme's .info file using filenames that match the core files then you override them, and if your overrides don't exist then they're not included.

See the .info file for the Tao theme for an example

I don't this will work but i think just remove the following line in your theme's page.tpl.php

 <?php echo $styles ?>

and then drupal will not any of its own styles..
this may be work for you.


Nitz
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!