Skip to content

Instantly share code, notes, and snippets.

@tmbritton
Created September 3, 2013 18:57
Show Gist options
  • Save tmbritton/6428077 to your computer and use it in GitHub Desktop.
Save tmbritton/6428077 to your computer and use it in GitHub Desktop.
Drupal add classes to <body> tag based on taxonomy terms.
/**
* Implements hook_preprocess_html().
* Add classes to <body> tag based on taxonomy terms.
*/
function wfm_static_preprocess_html(&$vars) {
$node = node_load(arg(1));
if ($node && $node->type === 'page') {
if (count($node->field_body_classes) > 0) {
foreach ($node->field_body_classes[LANGUAGE_NONE] as $term) {
$machine_name = drupal_html_class($term['taxonomy_term']->name);
$vars['classes_array'][] = $machine_name;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment