Last Updated: February 25, 2016
·
3.324K
· 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 ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside