{"id":520,"date":"2012-05-24T14:51:39","date_gmt":"2012-05-24T05:51:39","guid":{"rendered":"http:\/\/www.santoshkori.com\/blog\/?p=520"},"modified":"2012-05-24T14:53:55","modified_gmt":"2012-05-24T05:53:55","slug":"how-to-automatically-add-a-class-to-body_class-if-there%e2%80%99s-a-sidebar","status":"publish","type":"post","link":"https:\/\/www.santoshkori.com\/blog\/how-to-automatically-add-a-class-to-body_class-if-there%e2%80%99s-a-sidebar\/","title":{"rendered":"How to automatically add a class to body_class if there\u2019s a sidebar"},"content":{"rendered":"<p>To apply the hack, just paste the code below into your functions.php file to add automatically body class to body tag based on sidebar active.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction wpfme_has_sidebar($classes) {\r\n    if (is_active_sidebar('sidebar')) {\r\n        \/\/ add 'class-name' to the $classes array\r\n        $classes&#x5B;] = 'has_sidebar';\r\n    }\r\n    \/\/ return the $classes array\r\n    return $classes;\r\n}\r\nadd_filter('body_class','wpfme_has_sidebar');\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To apply the hack, just paste the code below into your functions.php file to add automatically body class to body tag based on sidebar active. function wpfme_has_sidebar($classes) { if (is_active_sidebar(&#8216;sidebar&#8217;)) { \/\/ add &#8216;class-name&#8217; to the $classes array $classes&#x5B;] = &#8216;has_sidebar&#8217;; } \/\/ return the $classes array return $classes; } add_filter(&#8216;body_class&#8217;,&#8217;wpfme_has_sidebar&#8217;);<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[184],"tags":[234,235,236,233],"class_list":["post-520","post","type-post","status-publish","format-standard","hentry","category-wordpress-tip-and-tricks","tag-how-to-automatically-add-a-class-to-body","tag-how-to-automatically-add-a-class-to-body-based-on-widget","tag-how-to-automatically-add-a-class-to-body-based-sidebar","tag-how-to-automatically-add-a-class-to-body_class-if-theres-a-sidebar"],"_links":{"self":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/520","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/comments?post=520"}],"version-history":[{"count":3,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/520\/revisions"}],"predecessor-version":[{"id":523,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/520\/revisions\/523"}],"wp:attachment":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/media?parent=520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/categories?post=520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/tags?post=520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}