Drupal add class to body if page is unpublished I would like to be able to add an unpublished class to the body tag of a node (for both its main view and edit view) if the node has been unpublished. 

How can I do this?



Steps I have taken:

1) Node Object
The node object contains if a node has been published or unpublished (with $node -&gt; Status), but I am not sure how to test this for each node and then add it to the body class.

This question is similar, but the provided answer doesn't work.

2) Drupal 6
This page explains how to do it for Drupal 6, but the code doesn't work for Drupal 7.
in your theme's template.php:

function mytemplate_preprocess_html(&amp;$vars) {
  $node = menu_get_object();
  if ($node &amp;&amp; isset($node-&gt;nid)) {
    if ($node-&gt;status) {
      $vars['classes_array'][] = 'published';
    } else {
      $vars['classes_array'][] = 'unpublished';
    }
  }
}