I want to remove default Drupal CSS files if it is a front page in Drupal 7 theme.

Following is the code (got from http://www.grahamgilchrist.com/blog/25) that I am trying to put in the template.php for barktik1 theme. How do I check if rendering page is a front page or not? Only $css variable is passed as an argument to the theme_css_alter() function while for other process functions $variables is passed from which it is easy to determine if it is a front page or not.

function bartik1_css_alter(&$css) { 

//do something to check if it is a front page
if ($is_front){
    //make a list of module css to remove 
    $css_to_remove = array(); 
    $css_to_remove[] = drupal_get_path('module','system').'/system.base.css'; 
    $css_to_remove[] = drupal_get_path('module','system').'/system.menus.css'; 

    // now we can remove the contribs from the array 
    foreach ($css_to_remove as $index => $css_file) { 


2 Answers 2


The function you're looking for is drupal_is_front_page().


In both Drupal 7 and 8 you have hook_css_alter for altering CSS files before output on the page.

If you want to remove some default css file from your Drupal 7 home page you can go with:

function YOUR_THEME_css_alter(&$css) {
  if (drupal_is_front_page() == TRUE  )  {
    unset($css['/'.drupal_get_path('theme', 'YOUR_THEME').'/css/removeme.css'] );

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.