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


  • 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. Commented Sep 6, 2012 at 12:50

2 Answers 2


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.


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' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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