WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] body_class - how do I know which class I'm in? (5 posts)

  1. octocore
    Member
    Posted 4 years ago #

    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 {
    background-color:#0033CC;
    }

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

    Thanks.

  2. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    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">
    or
    <body class="single postid-1">

  3. octocore
    Member
    Posted 4 years ago #

    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:
    http://www.louiesolomon.com

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

    body.home
    body.home.blog
    body.blog
    body.page-id-2

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

  4. Mark / t31os
    Moderator
    Posted 4 years ago #

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

    body.home { background-color:#000!important; }
  5. octocore
    Member
    Posted 4 years ago #

    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(); ?>>

Topic Closed

This topic has been closed to new replies.

About this Topic