Skip to content

Instantly share code, notes, and snippets.

@kayue
Created January 10, 2011 04:30
Show Gist options
  • Save kayue/772358 to your computer and use it in GitHub Desktop.
Save kayue/772358 to your computer and use it in GitHub Desktop.
Add categories to body class in WordPress
<?php
function _add_body_class($classes, $custom_classes = false)
{
the_post();
// insert buddypress class on buddypress page
if ( function_exists("bp_is_blog_page") && !bp_is_blog_page() )
$classes[] = 'buddypress';
// add category
if ( is_single() ) {
foreach (get_the_category() as $category) {
$classes[] = "single-".$category->slug;
}
}
rewind_posts();
return $classes;
}
add_filter("body_class", "_add_body_class", 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment