Drupal 7: Disable core and contrib css and js files

This is the way I disable core and contributed css files via theme. In you theme's template.php add following:


function your_theme_name_here_preprocess_html(&$vars) {
/**
* Reset all css files.
*/
drupal_static_reset('drupal_add_css');
/**
* Add theme css files.
*/
drupal_add_css(path_to_theme() .'/css/main.css', array('group' => CSS_THEME, 'every_page' => TRUE, 'weight' => -20));
/**
* Add innerpage.css theme css file if current page is not frontpage.
*/
if (!drupal_is_front_page()) {
drupal_add_css(path_to_theme() .'/css/innerpage.css', array('group' => CSS_THEME, 'every_page' => TRUE, 'weight' => -20));
}
/**
* Check if the current page is front page and remove innerpage.css file.
*/
if (drupal_is_front_page()) {
if (isset($css[drupal_get_path('theme','your_theme_name_here') .'/css/innerpage.css'])) {
unset($css[drupal_get_path('theme','your_theme_name_here') .'/css/innerpage.css']);
}
drupal_add_css(path_to_theme() .'/css/homepage.css', array('group' => CSS_THEME, 'every_page' => FALSE));
}
/**
* If user is logged in add system css files.
*/
if(user_is_logged_in() == 1) {
drupal_add_css(drupal_get_path('module', 'toolbar') . '/toolbar.css', array('group' => CSS_THEME));
drupal_add_css(drupal_get_path('module', 'system') . '/system.base.css', array('group' => CSS_SYSTEM, 'preprocess' => TRUE));
}
/**
* Reset all js files.
*/
drupal_static_reset('drupal_add_js');
/**
* Add theme js files.
*/
drupal_add_js(path_to_theme() . '/js/main.js', 'file');
/**
* If user is logged in add system js files.
*/
if(user_is_logged_in() == 1) {
drupal_add_js($GLOBALS['base_url'] .'/misc/drupal.js','file');
drupal_add_js(drupal_get_path('module', 'overlay') .'/overlay-parent.js', 'file');
drupal_add_js(drupal_get_path('module', 'toolbar') .'/toolbar.js', 'file');
}
/**
* Add theme if not frontpage js file.
*/
if (!drupal_is_front_page()) {
drupal_add_js(path_to_theme() . '/js/innerpage.js', 'file');
}
/**
* Add theme frontpage js file.
*/
if (drupal_is_front_page()) {
drupal_add_js(path_to_theme() . '/js/homepage.js', 'file');
}
}

Tags

Drupal 7: Disable core and contrib css and js files