Created
January 10, 2011 04:30
-
-
Save kayue/772358 to your computer and use it in GitHub Desktop.
Add categories to body class in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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