Title: Widget Background
Last modified: August 19, 2016

---

# Widget Background

 *  Resolved [cableghost](https://wordpress.org/support/users/cableghost/)
 * (@cableghost)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/widget-background-1/)
 * I found a number of solutions to changing the background color of widgets, but
   how might I change the widget background only when that widget appears on a specific
   page ID, or page range?
 * -Scott

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/widget-background-1/#post-1481944)
 * Use the classes generated by [body_class()](http://codex.wordpress.org/User:Esmi/body_class).
 *  Thread Starter [cableghost](https://wordpress.org/support/users/cableghost/)
 * (@cableghost)
 * [16 years ago](https://wordpress.org/support/topic/widget-background-1/#post-1482064)
 * Thank you esmi, but I am stuck.
 * I see in your example:
    `<?php body_class('$class'); ?>`
 * But how would I attach this to a specific widget, and would I place page ID with
   $class?
 * -Scott
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years ago](https://wordpress.org/support/topic/widget-background-1/#post-1482065)
 * Widgets all have unique IDs, you should be able to target them specifically without
   needing the body class (although it could be used to do the same).
 * Could you link to a page with the widget in question?
 *  Thread Starter [cableghost](https://wordpress.org/support/users/cableghost/)
 * (@cableghost)
 * [16 years ago](https://wordpress.org/support/topic/widget-background-1/#post-1482066)
 * [@t31os_](https://wordpress.org/support/users/t31os_/) Here is my test site: 
   [http://test.9001sites.com](http://test.9001sites.com)
 * We could look at the widget named ‘Recent Titles’ as an example, and have the
   background color changed only when viewing the VisoDerm post ([http://9001sites.com/test/visoderm/](http://9001sites.com/test/visoderm/))
 * -Scott
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years ago](https://wordpress.org/support/topic/widget-background-1/#post-1482067)
 * If you’re using the widget in several places you’ll need a way to differentiate,
   in which case, back to the body class (as emsi origianlly suggested)..
 * Open up your theme’s header.php and find the body tag..
 *     ```
       <body>
       ```
   
 * Update that to..
 *     ```
       <body <?php body_class(); ?>>
       ```
   
 * Which will then provide us with a definitive class and ID we can use to selectively
   target that page’s recent post widget(although it is in essence the same widget,
   just on a particular page).
 * Add that to the body and post back when you’re done, and i’ll help you with writing
   the css.. 🙂
 *  Thread Starter [cableghost](https://wordpress.org/support/users/cableghost/)
 * (@cableghost)
 * [16 years ago](https://wordpress.org/support/topic/widget-background-1/#post-1482076)
 * Pardon the delay; my test crashed and had to start over 😉
 * I have made the body change as directed.
 * -Scott
 *  Thread Starter [cableghost](https://wordpress.org/support/users/cableghost/)
 * (@cableghost)
 * [16 years ago](https://wordpress.org/support/topic/widget-background-1/#post-1482087)
 * I finally figured it out.
 * -Scott

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

The topic ‘Widget Background’ is closed to new replies.

## Tags

 * [background](https://wordpress.org/support/topic-tag/background/)
 * [css](https://wordpress.org/support/topic-tag/css/)
 * [widget](https://wordpress.org/support/topic-tag/widget/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 3 participants
 * Last reply from: [cableghost](https://wordpress.org/support/users/cableghost/)
 * Last activity: [16 years ago](https://wordpress.org/support/topic/widget-background-1/#post-1482087)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
