Is there any way to add the category class to the body tag? I need this so I can target css on specific categories
thx
Is there any way to add the category class to the body tag? I need this so I can target css on specific categories
thx
Hi granatdesign,
WordPress does this out-the-box for you. If you inspect your website using FireBug or Chromes dev tools whilst on your category page. You should have the following.
category category-NAME category-ID
Where I have NAME
and ID
, you need to replace them with your category name for example category-movies
and ID with the ID value of your category. You can find this by either inspecting your category page using FireBug or similar tool or hovering over your category name in the WordPress Admin Dashboard.
You can use those classes to prefix your styling like so:
.category-movie h1 {
color: red;
}
Thanks,
Danny
thanks for reply.
However, what I’m trying to get is a category class on a single post that is in a category, not the archive. Sorry if I was unclear.
For example, this post doesn’t show the category in the body class.
I figured out a way to add a class after the container, but would like to target before that, preferably in body class
thx
Hey Matt,
The codex provides a code for this. Check the link below.
https://codex.wordpress.org/Function_Reference/body_class#Add_Classes_By_Filters
Ben
thanks, Ben!
No worries! Have fun with BB!
Ben