I am trying to set to set the body’s class based on either the page name or the posts category. If I use the following conditional it works fine for setting the pages body class:
But when I introduce the in_category to the mix it stops working properly – to be more specific the conditionals before the use of the in_category work fine but everything after do not. Here is the code:
Please have a look and let me know if you can help me out.
Well my problem is that I want the body’s class to be set by the page slug when the user is on a page. When the user is viewing a post I would like the body’s class to be the posts category. I other words if I am on the front page the body class would be ‘home’ or if I am ready a post under the trips category the body’s class would be ‘trips’.
Setting the class using the pages slug works fine. When I try to set it using the category things get a little weird (as described in my initial post).
Ok, I understand what the body_class does but how do I get it to print the pages slug to a pages body class or the category’s name to the posts body class?
Right now when you view a page this is what the body tag looks like:
Or when you are reading a post this is what the body tag looks like:
I need the pages slug and or category name to be included in the class so I can target them with specific CSS. For example, if I am reading a post under the trips category the body tag would look like this:
I am sorry for being such a nuisance but I really am at a loss.