5

Adding a stylesheet to specific pages is easy: implement hook_preprocess_page(), call drupal_add_css(...) and set $vars['styles'] = drupal_get_css().


But what is the proper way to remove a stylesheet (or in my case, all "media=screen" stylesheets) for a specific page, without interfering with the caching system ? (e.g. not some regex applied to the output)

You can't just do unset($vars['css']['screen']) because $vars['styles'] has already been generated at this point and there exists no drupal_remove_css() function.

8

This seems to be the cleanest way, in hook_preprocess_page():

$css = drupal_add_css();
unset( $css['screen'] );
$vars['styles'] = drupal_get_css($css);
| improve this answer | |

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.