{"id":447,"date":"2011-07-25T08:44:39","date_gmt":"2011-07-25T08:44:39","guid":{"rendered":"http:\/\/wp4design.com\/?p=447"},"modified":"2012-02-26T15:44:35","modified_gmt":"2012-02-26T14:44:35","slug":"add-singular-class-body-tag","status":"publish","type":"post","link":"http:\/\/4design.xyz\/wordpress-basics\/add-singular-class-body-tag","title":{"rendered":"Add a .singular class within the body tag"},"content":{"rendered":"<p>The <em>is_singular()<\/em> <a href=\"http:\/\/codex.wordpress.org\/Conditional_Tags\">conditional tag<\/a> check if the user is displaying a single post, a single page or an attachment, which are respectively check with <em>is_single()<\/em>, <em>is_page()<\/em> and <em>is_attachment()<\/em>. With these conditional tags come three usefull classes nested in the body tag: <em>.single<\/em>, <em>.page<\/em> or <em>.attachment<\/em>. But, no <em>.singular<\/em> classe to rule them all!<!--more--><\/p>\n<p>So, I put in \u2665\u00a0Basics a function to fix that:<\/p>\n<pre>\/**\n* Add custom body classes\n*\/\nadd_filter( 'body_class', 'basics_body_class' );\nif ( ! function_exists( 'basics_body_class' ) ) :\n    function basics_body_class($classes) {\n        if ( is_singular() )\n        $classes[] = 'singular';\n        return $classes;\n    }\nendif;<\/pre>\n<p>The result is that instead of using a long selector like .single, .page, .attachment { &#8230; } you just have to specify .singular { &#8230; }<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The is_singular() conditional tag check if the user is displaying a single post, a single page or an attachment, which are respectively check with is_single(), is_page() and is_attachment(). With these conditional tags come three usefull classes nested in the body tag: .single, .page or .attachment. But, no .singular classe to rule them &hellip; <a href=\"http:\/\/4design.xyz\/wordpress-basics\/add-singular-class-body-tag\" rel=\"nofollow\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[8,10,11,12,25,30,57,82,86,87,88],"_links":{"self":[{"href":"http:\/\/4design.xyz\/wordpress-basics\/wp-json\/wp\/v2\/posts\/447"}],"collection":[{"href":"http:\/\/4design.xyz\/wordpress-basics\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4design.xyz\/wordpress-basics\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4design.xyz\/wordpress-basics\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/4design.xyz\/wordpress-basics\/wp-json\/wp\/v2\/comments?post=447"}],"version-history":[{"count":0,"href":"http:\/\/4design.xyz\/wordpress-basics\/wp-json\/wp\/v2\/posts\/447\/revisions"}],"wp:attachment":[{"href":"http:\/\/4design.xyz\/wordpress-basics\/wp-json\/wp\/v2\/media?parent=447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4design.xyz\/wordpress-basics\/wp-json\/wp\/v2\/categories?post=447"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4design.xyz\/wordpress-basics\/wp-json\/wp\/v2\/tags?post=447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}