1

When i add drupal_add_library('system', 'ui.accordion'); to my template.php, 3 jquery css files are loaded, but i can't remove them with $css_to_remove[] = drupal_get_path('misc','ui').'/jquery.ui.core.css'; (i tried some paths, but none worked).

Can anyone tell me how to remove CSS files loaded by jquery libraries? Thanks

4

This code will help you. Add it to your template.php:

function THEME_NAME_css_alter(&$css) {
  // List of disabled drupal default css files.
  $disabled_drupal_css = array(
    // Remove jquery.ui css files.
    'misc/ui/jquery.ui.core.css',
    'misc/ui/jquery.ui.theme.css',
  );

  // Remove drupal default css files.
  foreach ($css as $key => $item) {
    if (in_array($key, $disabled_drupal_css)) {
      // Remove css and its altered version that can be added by jquety_update.
      unset($css[$css[$key]['data']]);
      unset($css[$key]);
    }
  }
}

If you want to remove some other css - just print_r $css variable to get its name and add it to $disabled_drupal_css.

  • Many thanks for your answer, it works perfectly. How is this different from $css_to_remove[] = drupal_get_path('module','ckeditor').'/ckeditor.css';? – Federico Arena Jul 31 '12 at 16:47
  • If you want remove css styles from CKeditor you can add line: $disabled_drupal_css[] = drupal_get_path('module','ckeditor').'/ckeditor.css'; – Eugene Fidelin Aug 1 '12 at 8:00
0

You have to use exactly the same name as the stylesheet you want to remove.

You could do that even in your theme .info file. The file does not need to exist, it is enough if you just add this line there:

stylesheets[all][] = jquery.ui.core.css

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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