{"id":1023168,"date":"2015-11-09T04:57:48","date_gmt":"2015-11-09T12:57:48","guid":{"rendered":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/add-category-name-as-body_class\/"},"modified":"2015-11-19T17:18:38","modified_gmt":"2015-11-20T01:18:38","slug":"add-category-name-as-body_class","status":"closed","type":"topic","link":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/add-category-name-as-body_class\/","title":{"rendered":"Add Category name as body_class"},"content":{"rendered":"<p>Hello,<\/p>\n<p>The category name isn&#8217;t added to body classes on the single-event pages.<br \/>\nI tried to do it from my function.php<br \/>\n<code>function category_id_class( $classes ) {<br \/>\n\tglobal $post;<br \/>\n        \/\/testing<br \/>\n        echo $post-&gt;ID;<br \/>\n}<br \/>\nadd_filter( 'body_class', 'category_id_class' );<\/code><\/p>\n<p>But $post-&gt;ID isn&#8217;t set at that time. Although it is on &#8216;regular&#8217; WP pages.<br \/>\nHow should I achieve it ?<\/p>\n<p>Thanks by advance,<br \/>\nThib<\/p>\n","protected":false},"template":"","class_list":["post-1023168","topic","type-topic","status-closed","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Add Category name as body_class -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/add-category-name-as-body_class\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Add Category name as body_class -\" \/>\n<meta property=\"og:description\" content=\"Hello, The category name isn&#8217;t added to body classes on the single-event pages. I tried to do it from my function.php function category_id_class( $classes ) { global $post; \/\/testing echo $post-&gt;ID; } add_filter( &#039;body_class&#039;, &#039;category_id_class&#039; ); But $post-&gt;ID isn&#8217;t set at that time. Although it is on &#8216;regular&#8217; WP pages. How should I achieve it [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/add-category-name-as-body_class\/\" \/>\n<meta property=\"article:modified_time\" content=\"2015-11-20T01:18:38+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/add-category-name-as-body_class\/\",\"url\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/add-category-name-as-body_class\/\",\"name\":\"Add Category name as body_class -\",\"isPartOf\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\"},\"datePublished\":\"2015-11-09T12:57:48+00:00\",\"dateModified\":\"2015-11-20T01:18:38+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/add-category-name-as-body_class\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/add-category-name-as-body_class\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/add-category-name-as-body_class\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/theeventscalendar.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Topics\",\"item\":\"https:\/\/theeventscalendar.com\/support\/topics\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Welcome!\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/_welcome\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Pre-Sales Questions\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/_welcome\/pre-sales-questions\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Add Category name as body_class\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\",\"url\":\"https:\/\/theeventscalendar.com\/support\/\",\"name\":\"\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Add Category name as body_class -","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/add-category-name-as-body_class\/","og_locale":"en_US","og_type":"article","og_title":"Add Category name as body_class -","og_description":"Hello, The category name isn&#8217;t added to body classes on the single-event pages. I tried to do it from my function.php function category_id_class( $classes ) { global $post; \/\/testing echo $post-&gt;ID; } add_filter( 'body_class', 'category_id_class' ); But $post-&gt;ID isn&#8217;t set at that time. Although it is on &#8216;regular&#8217; WP pages. How should I achieve it [&hellip;]","og_url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/add-category-name-as-body_class\/","article_modified_time":"2015-11-20T01:18:38+00:00","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/add-category-name-as-body_class\/","url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/add-category-name-as-body_class\/","name":"Add Category name as body_class -","isPartOf":{"@id":"https:\/\/theeventscalendar.com\/support\/#website"},"datePublished":"2015-11-09T12:57:48+00:00","dateModified":"2015-11-20T01:18:38+00:00","breadcrumb":{"@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/add-category-name-as-body_class\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/theeventscalendar.com\/support\/forums\/topic\/add-category-name-as-body_class\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/add-category-name-as-body_class\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/theeventscalendar.com\/support\/"},{"@type":"ListItem","position":2,"name":"Topics","item":"https:\/\/theeventscalendar.com\/support\/topics\/"},{"@type":"ListItem","position":3,"name":"Welcome!","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/_welcome\/"},{"@type":"ListItem","position":4,"name":"Pre-Sales Questions","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/_welcome\/pre-sales-questions\/"},{"@type":"ListItem","position":5,"name":"Add Category name as body_class"}]},{"@type":"WebSite","@id":"https:\/\/theeventscalendar.com\/support\/#website","url":"https:\/\/theeventscalendar.com\/support\/","name":"","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1023168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1023168\/revisions"}],"predecessor-version":[{"id":1023169,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1023168\/revisions\/1023169"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/media?parent=1023168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}