Skip to content

Instantly share code, notes, and snippets.

@spencejs
Created March 22, 2013 03:29
Show Gist options
  • Save spencejs/5218739 to your computer and use it in GitHub Desktop.
Save spencejs/5218739 to your computer and use it in GitHub Desktop.
Add Categories For a Post As Class Names On The Body Tag - Wordpress
// add category nicenames in body and post class
function category_id_class($classes) {
global $post;
foreach((get_the_category($post->ID)) as $category)
$classes[] = $category->category_nicename;
return $classes;
}
add_filter('post_class', 'category_id_class');
add_filter('body_class', 'category_id_class');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment