WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to change themes background color using a plugin. For when I use this code,

function change_background_of_theme(){

#main{background: yellow;}



This code only changes the bg color of the theme that use #main id. This basically leads to another question, is there a common id that themes use for background or something close to that. I appreciate your assistance. :)


share|improve this question
There is really no way to do that, almost every second theme uses different div structure. What you could do is let the user specify div or class. – OriginalEXE Sep 6 '12 at 12:50
Thanks thats what I thought. :) – Ronny Sep 6 '12 at 12:50

If the theme uses the custom-background functionality of WordPress, then WordPress outputs CSS code in the head which essentially says body.custom-background { ... } and it puts the chosen colors and image in there.

So most themes sorta expect that to be on the body itself, and to have a custom-background class on the body tag.

share|improve this answer
Thanks Otto... I see your point. :) – Ronny Sep 6 '12 at 12:54

If the plugin uses the custom-background, then you can switch easily, updating the "theme_mods_{$name}" option:

/** Plugin Name: (#64373) Custom background Color */
function wpse64373_set_custom_background( $new_colour )
    $old_colour = get_theme_mod(
        ,get_theme_support( 'custom-background', 'default-color' )

    // Nothing to do here
    if ( $old_colour == $new_colour )

    return set_theme_mod( 'background_color', $new_colour );
function wpse64373_update_custom_background()
    // Not sure if we have to prepend a `#`
    wpse64373_set_custom_background( '009EE0' );
add_action( 'init', 'wpse64373_update_custom_background' );
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.