Support » Fixing WordPress » Widget Background

  • Resolved cableghost


    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?


Viewing 7 replies - 1 through 7 (of 7 total)
  • Use the classes generated by body_class().

    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?


    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?

    @t31os_ Here is my test site:

    We could look at the widget named ‘Recent Titles’ as an example, and have the background color changed only when viewing the VisoDerm post (


    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..


    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.. 🙂

    Pardon the delay; my test crashed and had to start over 😉

    I have made the body change as directed.


    I finally figured it out.


Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Widget Background’ is closed to new replies.