4

I am trying to make different layout for the front page. In that process I declared new stylesheet called "front-page.css" and page--front.tpl.php. I am using a Zen subtheme which loads responsive-sidebar.css. I want to remove "responsive-sidebar.css" and load "front-page.css". The reason I am doing it because the number of grind columns in the later stylesheet is different that former.

I don't want to use Panels module. I am using Drupal 7.

Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
rockvilla
  • 641
  • 8
  • 15

4 Answers4

2

Inside your theme's template.php file and inside the template_preprocess_page($vars), find the CSS file you want to remove inside $vars['stylesheets'] and use PHP's unset function to remove it from the $vars['stylesheets'] array.

halfer
  • 19,824
  • 17
  • 99
  • 186
Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
  • This would work in Drupal 6 but stylesheets key is not present in $vars array in Drupal 7. D7 has changed the way to do it! – rockvilla Jan 02 '13 at 11:47
2

The Drupal 7 way is to use hook_css_alter():

function MYMODULE_css_alter(&$css) {
  // Remove defaults.css file. The path will probably change for your theme obviously.
  unset($css[drupal_get_path('theme', 'MYTHEME') . '/css/responsive-sidebar.css']);
}

That hook can be implemented in either a module or a theme.

Clive
  • 36,918
  • 8
  • 87
  • 113
0

I just found better way to do this. It is bit hacky, but allows to unset css at almost any place:

$css = &drupal_static('drupal_add_css', array());
unset($css['some_css_path']);
Mantas
  • 222
  • 1
  • 7
0

Drupal 8 way. Maybe it works in Drupal 7. For remove stylesheet on a certain/specific page you need:

function MYTHEME_css_alter(&$css) {

// Get me path:
  $current_path = \Drupal::service('path.current')->getPath();
  $result = \Drupal::service('path.alias_manager')->getAliasByPath($current_path);

    if ($result == 'your/path' ){
      unset($css[drupal_get_path('theme', 'THEMENAME') . '/css/style.css']);
    }
}

It works for me in D8 and can put it in .theme or .module. You need delete all caches (or module caches) necessarily.