Con questa funzione php รจ possibile aggiungere in automatico nelle classi del body la lista dei nomi di categoria associate ad un post. Incolla questo codice nel file functions.php nel tema child o tema padre.
function studio42_add_post_category_names_to_body_class($classes) {
if (is_single() ) {
global $post;
$categories = get_the_category($post->ID);
foreach( $categories as $category) {
$classes[] = 'cat-' . $category->category_nicename;
}
}
return $classes;
}
add_filter('body_class','studio42_add_post_category_names_to_body_class');