Add Category Name to body_class ( Wordpress )

The body_class function is nice for adding a classes to the body tag that have information about what kind of page is currently being displayed.

function add_category_to_single($classes) {
 if (is_single() ) {
  global $post;
  foreach((get_the_category($post->ID)) as $category) {
   // add category slug to the $classes array
   $classes[] = $category->category_nicename;
 // return the $classes array
 return $classes;

Related Post

Latest Post

Recent Posts Widget

Make sure to never miss a thing...

Get the latest news from the creative industry along with other creative goodies, conveniently delivered to social media.