Pedro Posada | Remove or disable style sheets for single node on Drupal
You can't request more than 20 challenges without solving them. Your previous challenges were flushed.

Remove or disable style sheets for single node on Drupal

Posted on August 28, 2009 - 3:09pm
<< 14 of 54 >>

I wanted to make one of the pages in my site look and feel completely different than the rest of the site. I wanted to use a different style sheet css file for this page and also didn't want to override all the existing styles.

I found a very good post about it on http://drupal.org/node/258756

This code goes inside template.php

<?php

function phptemplate_preprocess_page(&$vars){

if(
$node = menu_get_object()){ // we check if the current page is a node
 
if($node->nid == 10){ //  this is the page we want to modify, node/10
  
$css = $vars['css'];
   unset(
$css['all']['module']['modules/system/system.css']);
   unset(
$css['all']['module']['modules/system/defaults.css']);
  
$vars['styles'] = drupal_get_css($css);
  }
}
}
?>

The structure of the $vars['css'] variable looks something like this:

Array
(
    [all] => Array
        (
            [module] => Array
                (
                    [modules/node/node.css] => 1
                    [modules/system/defaults.css] => 1
                    [modules/system/system.css] => 1
                    [modules/system/system-menus.css] => 1
                    [modules/user/user.css] => 1
                    [sites/all/modules/admin_menu/admin_menu.css] =>
                )

            [theme] => Array
                (
                    [sites/all/themes/mytheme/layout.css] => 1
                )

        )

    [print] => Array
        (
            [module] => Array
                (
                )

            [theme] => Array
                (
                    [sites/all/themes/interactivemale/print.css] => 1
                )

        )

)

Submitted by James Williams (not verified) on July 27, 2011 - 10:55pm.

Drupal is a great language and is widely used now-a-days in web development. So keeping the codes updated and clear will help a lot and will create less confusion. Also the maintainence would be easy. Thanks for the template. It was very interesting.
accredited online colleges

Submitted by dustin buttry (not verified) on August 12, 2011 - 4:12am.

Thanks for the post but...I found another solution to control the default styles -
not to use the general default stylesheet files, but instead of it
to copy, change and redirect the default stylesheet files for my concrete new theme.
frontline plus for cats

Submitted by andrew peters (not verified) on August 26, 2011 - 3:29am.

With drupal 6.x, you can use the theme.info file to overwrite the default system css files. For example, to over write the system menu default styling simply add:
stylesheets[all][] = system-menus.css
knol.google.com

Submitted by proness dan (not verified) on September 9, 2011 - 11:44pm.

Isn't there an easy way to hide the node title by using an in line css override? so not to have to edit any files.
multi zone amplifier

Submitted by brian antony (not verified) on September 25, 2011 - 11:02pm.

The logic is that this is how it worked in Drupal 6, and we (themers/designers) like it because it's easy. This is a very widely used and recommended technique for removing CSS files.
patent translation

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Copy the characters (respecting upper/lower case) from the image.