Title: body_class conditional
Last modified: August 21, 2016

---

# body_class conditional

 *  Resolved [TatsujinUK](https://wordpress.org/support/users/tatsujinuk/)
 * (@tatsujinuk)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/body_class-conditional/)
 * I’m trying to target the body_class from within a specific php template file.
 * Essentially, each page within the site has its own unique body class, and I’m
   trying to add into the php template file (not the functions file) some code to
   add some additional code (a slider) if the body_class matches and is left empty
   if it doesn’t match.
 * Something like:
 * <?php if ( body_class(‘term-business-practices-and-policies’) ) {?>
    // add slider
   code here <?php } ?>
 * There will actually be 4 or 5 specific instances I need to target, each with 
   different code (image)
 * Any ideas?

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/body_class-conditional/#post-4826760)
 * try and work with `get_body_class()` [https://codex.wordpress.org/Function_Reference/get_body_class](https://codex.wordpress.org/Function_Reference/get_body_class)
 * example (untested):
 *     ```
       <?php if ( in_array( 'term-business-practices-and-policies', get_body_class() ) ) {?>
       // add slider code here
       <?php } ?>
       ```
   
 * [http://uk1.php.net/in_array](http://uk1.php.net/in_array)
 * or try these conditional tags:
    [http://codex.wordpress.org/Function_Reference/is_page](http://codex.wordpress.org/Function_Reference/is_page)
   [http://codex.wordpress.org/Function_Reference/is_page_template](http://codex.wordpress.org/Function_Reference/is_page_template)
 *  Thread Starter [TatsujinUK](https://wordpress.org/support/users/tatsujinuk/)
 * (@tatsujinuk)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/body_class-conditional/#post-4826841)
 * alchymyth – you are a star, that code worked perfectly for what we wanted to 
   do.
 * Thank you very much!
 * Chris
    [](http://www.cmykreative.com)

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

The topic ‘body_class conditional’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [TatsujinUK](https://wordpress.org/support/users/tatsujinuk/)
 * Last activity: [12 years, 1 month ago](https://wordpress.org/support/topic/body_class-conditional/#post-4826841)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
