Last Updated: February 25, 2016
·
3.013K
· balaclark

Drupal 7: add a body class for taxonomy vocabulary machine names

Need to style a taxonomy page differently? Add a body class:

function your_module_preprocess_html(&$variables) {
  if (arg(0) == 'taxonomy' && arg(1) == 'term') {
    $term = taxonomy_term_load(arg(2));
    $variables['classes_array'][] = 'vocabulary-' . strtolower($term->vocabulary_machine_name);
  }
}

Now you you add vocabulary specific styles to the whole page in your css file:

.vocabulary-machine_name {
  /* code */
}

1 Response
Add your response

I add this function into template.php and it doesn't work

over 1 year ago ·