- 546 views
Add the code in your .theme file
Use HOOK_preprocess_html() function and copy the following example to your code:
function HOOK_preprocess_html(&$variables) {
if (\Drupal::routeMatch()->getRouteName() == 'entity.taxonomy_term.canonical') {
// load the term entity and get the data from there
$term = \Drupal::routeMatch()->getParameter('taxonomy_term');
$variables['term_id'] = $term->id();
$variables['vocabulary_id'] = $term->bundle();
$variables['attributes']['class'][] = 'taxonomy_' . $variables['vocabulary_id'];
}
}
Use your new CSS class
Do not forget to clear the cache if you do not have hook already registered.
You new class should be like taxonomy_MACHINE_NAME and you can widely use it in your CSS now.