{"id":10068,"date":"2016-10-19T10:14:48","date_gmt":"2016-10-19T09:14:48","guid":{"rendered":"http:\/\/themes.artivity.co.uk\/basix\/?p=10068"},"modified":"2016-10-19T10:14:48","modified_gmt":"2016-10-19T09:14:48","slug":"10068-2","status":"publish","type":"post","link":"https:\/\/ceteris-paribus.com\/en\/10068-2\/","title":{"rendered":"Add Category to the Body Class in WordPress"},"content":{"rendered":"<p>WordPress doesn&#8217;t include the category in the body classes by default, so stick this in your functions.php and hey presto, the category will be added for each post with a category assigned to it.<\/p>\n<pre class=\"lang:php decode:true \">function add_category_to_single($classes, $class) {\n  if (is_single() ) {\n    global $post;\n    foreach((get_the_category($post-&gt;ID)) as $category) {\n      \/\/ add category slug to the $classes array\n      $classes[] = $category-&gt;category_nicename;\n    }\n  }\n  \/\/ return the $classes array\n  return $classes;\n}\n\nadd_filter('body_class','add_category_to_single');<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress doesn\u2019t include the category in the body classes by default, so stick this in your functions.php and hey presto, the category will be added for each post with a category assigned to it.<\/p>\n","protected":false},"author":1,"featured_media":10541,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,1],"tags":[32],"class_list":["post-10068","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code-snippets","category-uncategorized","tag-wordpress"],"translation":{"provider":"WPGlobus","version":"3.0.2","language":"en","enabled_languages":["es","en"],"languages":{"es":{"title":true,"content":true,"excerpt":true},"en":{"title":false,"content":false,"excerpt":false}}},"_links":{"self":[{"href":"https:\/\/ceteris-paribus.com\/en\/wp-json\/wp\/v2\/posts\/10068","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ceteris-paribus.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ceteris-paribus.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ceteris-paribus.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ceteris-paribus.com\/en\/wp-json\/wp\/v2\/comments?post=10068"}],"version-history":[{"count":0,"href":"https:\/\/ceteris-paribus.com\/en\/wp-json\/wp\/v2\/posts\/10068\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ceteris-paribus.com\/en\/wp-json\/wp\/v2\/media\/10541"}],"wp:attachment":[{"href":"https:\/\/ceteris-paribus.com\/en\/wp-json\/wp\/v2\/media?parent=10068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ceteris-paribus.com\/en\/wp-json\/wp\/v2\/categories?post=10068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ceteris-paribus.com\/en\/wp-json\/wp\/v2\/tags?post=10068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}