Support » Themes and Templates » body_class – how do I know which class I’m in?

  • Resolved octocore


    Hello, and thanks for looking.

    I have a simple problem. I’d like to be able to change the background color depending on which page I’m on. Would the body_class function be a good way of doing this, and if so, how do I know which class to use?

    For example, would I use CSS like:

    #body .home {

    to do this? (this didn’t work by the way..), or is there a better solution?


Viewing 4 replies - 1 through 4 (of 4 total)
  • Michael


    Forum Moderator

    the right style to use would be:

    body.home {}

    to know the class(es) look at the html code in the browser and look for something like:
    <body class="home blog logged-in">
    <body class="single postid-1">

    I see what you’re saying about finding the class in the source code, but I can’t seem to get the background color to change.

    here’s my site:

    I’ve tried using a few different CSS lines, none of which seem to work when I add a background color attribute:


    Any idea what I’m doing wrong? Thanks again.

    body.home would be correct, just try forcing the style..

    body.home { background-color:#000!important; }

    Thanks for the reply. I figured out the problem. In the theme I was using, the body class code was written:

    <body class=<?php body_class(); ?>>

    instead of the proper

    <body <?php body_class(); ?>>

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘body_class – how do I know which class I’m in?’ is closed to new replies.