A better body_class for WordPress 2.8

by Moises Kirsch

WordPress 2.8 introduced a very useful new tag called body_class which normally will be used like this:

<body <?php body_class(); ?>>

The only problem is that it uses the ID’s instead of the page slugs making it a little harder to use the classes on your CSS (or Javascript).

A very easy way to fix this is to call the function with an argument like this:

<body <?php body_class( str_ireplace( '/', ' ', get_page_uri($post->ID) ) ); ?>>

What we are doing is adding the permalink structure as classes. That way you could target all the pages with the same parent, from the same category or so on without needing to know the ID. This is great if you are developing a theme and there is no way for you to know the ID of certain category or page.