Title: Help using body_class()
Last modified: August 22, 2016

---

# Help using body_class()

 *  Resolved [derpaa](https://wordpress.org/support/users/derpaa/)
 * (@derpaa)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/help-using-body_class/)
 * Hi, I am trying my hand at making my first custom page template and I am new 
   to php. My understanding is that I can use the body_class function to change 
   the background image and color of the overall page for this specific template,
   but I am having trouble using it.
 * I put <body <?php body_class(); ?>> as the body tag in the header.php file, but
   I don’t understand where and how in the TEMPLATE file I set which body class 
   it should use, or how that gets passed to the header file.
 * The tutorials I’m reading say that you pass your custom class as a function argument
   to body_class(), as in:
 * <body <?php body_class(‘my-class’); ?>>
    But this doesn’t seem like it would 
   work since the header file is for EVERY page. Can I set the body class id in 
   the template and get it to pass to the header’s body tag somehow, or how do you
   do this?
 * Thank you for any assistance you can provide!

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/help-using-body_class/#post-5736548)
 * It isn’t technically required to pass an argument to `body_class()` for this 
   purpose. When you use custom page template “foo.php”, you’ll have a class named`
   page-template-foo-php` on your `<body>` tag, which you can target with CSS normally:
 * `body.page-template-foo-php { background: url(path/to/image); }`
 *  Thread Starter [derpaa](https://wordpress.org/support/users/derpaa/)
 * (@derpaa)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/help-using-body_class/#post-5736552)
 * Ahhh, thank you very much!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Help using body_class()’ is closed to new replies.

## Tags

 * [body_class](https://wordpress.org/support/topic-tag/body_class/)
 * [page template](https://wordpress.org/support/topic-tag/page-template/)

 * 2 replies
 * 2 participants
 * Last reply from: [derpaa](https://wordpress.org/support/users/derpaa/)
 * Last activity: [11 years, 4 months ago](https://wordpress.org/support/topic/help-using-body_class/#post-5736552)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
