Does anyone know how to modify or filter the body_class() output to get a category name or slug as a body class for single posts?
Right now, for single posts it only outputs something like:
<body class="single postid-481">
Thanks,
Michael
Does anyone know how to modify or filter the body_class() output to get a category name or slug as a body class for single posts?
Right now, for single posts it only outputs something like:
<body class="single postid-481">
Thanks,
Michael
<?php $class='';
if(is_single()) {
$category = get_the_category();
$class .= $category[0]->slug;
}?>
<body id="top" <?php if (function_exists('body_class')) body_class($class ); ?>>Thanks! That worked perfectly... Would you know how to modify to get the parent category slug as well?
thanks esmi!
This is great, however it only puts the category slug into the body class
<body id="top" <?php if (function_exists('body_class')) body_class('category'.$class ); ?>>
to so it inserts category-slug
You must log in to post.