How can I modify body class based on non-taxonomy node data? I need to add a custom class to my html &lt;body&gt; tag when certain elements are present in content (namely, either a featured image or image gallery, both of which are added to content using Entity Reference fields in the site's main content types).

Currently I'm accomplishing this using the Context module and a taxonomy vocabulary.  (Condition: Taxonomy; Reaction: Theme HTML).  The workflow for content managers looks like this:


Add an image or gallery to a content item
Don't forget to attach the appropriate taxonomy term so the page lays out correctly.


Oddly enough, forgetting step 2 is a rampant problem.

Any suggestions on methods for eliminating step 2?  It seems like it ought to be possible to just test for the presence of a value in the appropriate fields and either automatically attach the taxonomy term, or skip the taxonomy term and trigger the theme HTML based on the data values themselves.  

I should mention that the taxonomy vocabulary in question has NO purpose in my application other than applying the appropriate body class.

I'm open to using some other module to accomplish this.  (Rules?  Couldn't figure out how to make this work either).

(Drupal 7).
You could do this in your theme's template.php. Something like this:

function mytheme_preprocess_html(&amp;$vars) {

  // Load node
  $node = menu_get_object();
  if ($node) {

    // Wrap to fetch field values easily 
    $wrapper = entity_metadata_wrapper('node', $node);

    // Check image reference fields and add body class
    if (
      $wrapper-&gt;field_featured_image-&gt;raw() ||
      $wrapper-&gt;field_image_gallery-&gt;raw()
    ) {
      $vars['classes_array'][] = 'my-class';
    }
  }
}