1

I'm using Drupal 7.

I want to disable css defined by theme because I want to use my custom css that is defined by my custom module. What I mean is, I want to disable sites/all/themes/custom_theme/css/custom.css and use sites/all/modules/custom_module/css/custom.css instead.

Is there any way to do that?

Thanks!

2 Answers 2

1

Yes.

What you want is to include call drupal_add_css() for example:

drupal_add_css(drupal_get_path('module', 'your_module') . '/css/custom.css', array('group' => CSS_DEFAULT, 'every_page' => TRUE));

What that does is that it adds the css file on every page load. You can read more about adding css files here: https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_css/7

In your theme's .info file you will find a section describing where to find the css file e.g:

stylesheets[all][] = css/style.css

simply switch it off by placing a ; at the start of that line. This works particularly well if your theme is a subtheme, that is based off some other theme that you don't want to change directly in case you may need to upgrade it later.

Lastly, should you decide to remove the css file from your template.php file or module, you can do that via hook_css_alter()

for example:

function hook_css_alter (&$css) {

    if (isset ($css[path_to_theme() . '/css/custom.css'])) {
        unset ($css[path_to_theme() . '/css/custom.css']);
    }

}

Hope it helps.

0
0

Chiko's answer is spot-on. You can also tweak the css_alter so that you can switch css off and on again by using TRUE and FALSE, such as this:

function MYTHEME_css_alter(&$css) {
$exclude = array(
    'modules/syslog/syslog.css' => FALSE,
    'modules/system/admin.css' => FALSE,
    'modules/system/maintenance.css' => FALSE,
    'modules/system/system.css' => FALSE,
    'modules/system/system.admin.css' => FALSE,
    'modules/system/system.maintenance.css' => FALSE,
    'modules/system/system.menus.css' => FALSE,
    'modules/system/system.messages.css' => FALSE,
    'modules/system/system.theme.css' => FALSE,
    'modules/taxonomy/taxonomy.css' => FALSE,
    'modules/tracker/tracker.css' => FALSE,
    'modules/update/update.css' => TRUE,
    'modules/user/user.css' => FALSE,
);
$css = array_diff_key($css, $exclude);

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.