I'm trying to add some other classes to my body in order to identify some pages. I've tried adding some classes, but for some reason drupal is not displaying them in the body.

Below is my preprocess_html and the output of $vars['classes_array'] and the actual output in html.

As you can see, only the class I added is not being displayed.

function theme_preprocess_html(&$vars) {
    $vars['classes_array'][] = drupal_html_class('page-' . $vars['head_title_array']['title']);

// output
array(10) {
  string(4) "html"
  string(9) "not-front"
  string(9) "logged-in"
  string(11) "no-sidebars"
  string(9) "page-node"
  string(10) "page-node-"
  string(12) "page-node-41"
  string(14) "node-type-page"
  string(7) "i18n-en"
  string(10) "page-legal"

// page output
class="html not-front logged-in page-node page-node- page-node-41 node-type-page i18n-en context-legal omega-mediaqueries-processed admin-menu responsive-layout-normal"
  • For what I can see, it seems to be completely ignoring this code
    – woutr_be
    Feb 3, 2012 at 6:06
  • So apparently $attributes also contains the body classes, but they don't get changes via $vars['classes_array']
    – woutr_be
    Feb 3, 2012 at 7:14
  • Is your function actually running? Is your function really named theme_ or is theme_ replaced with your actual theme's name? Feb 3, 2012 at 12:55
  • Yes, it is running, I posted the output of a var_dump in the function ...
    – woutr_be
    Feb 3, 2012 at 14:47

1 Answer 1


I don't know how your html.tpl.php looks like, since that will effect it, but by default the interesting line looks like this:

<body class="<?php print $classes; ?>" <?php print $attributes;?>>

So what you want to alter is not $vars['classes_array'] but $vars['classes']. This might explain why

context-legal omega-mediaqueries-processed admin-menu responsive-layout-normal

is printed out, but not in the $vars['classes_array'] array.

  • Thanks, I temporarily changed it by combining $classes and $attributes in one variable. But I guess yours is a better way.
    – woutr_be
    Feb 4, 2012 at 13:54

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.