Target single post of a certain category for styling
A single post doesn’t inject the category class at the page body class by default. Here is a PHP snippet that will add the category slug to the single post body.
add_filter('body_class','add_category_to_single'); function add_category_to_single($classes) { if (is_single() ) { global $post; foreach((get_the_category($post->ID)) as $category) { // add category slug to the $classes array $classes[] = $category->category_nicename; } } // return the $classes array return $classes; }
You can then target it with CSS like so (add appropriate category slug).
.single-post.category-slug { CSS Rules here }
This solution is theme-agnostic and should work for ALL WordPress themes.