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 */
}
Written by Bala Clark
Related protips
1 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
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#