Php 在主题加载时设置背景色

Php 在主题加载时设置背景色,php,wordpress,colors,Php,Wordpress,Colors,我正在尝试让我的Wordpress Twenty12子主题确保当主题被激活时背景是白色的。我不能只是将CSS添加到wp_头部,因为这样用户就无法设置自定义背景 我一直在看后设置主题挂钩 function set_white_bg() { set_theme_mod( custom-background, 'ffffff'); } add_action('after_setup_theme', 'set_white_bg'); 我也尝试过这一点,但运气不好 function wpse6

我正在尝试让我的Wordpress Twenty12子主题确保当主题被激活时背景是白色的。我不能只是将CSS添加到wp_头部,因为这样用户就无法设置自定义背景

我一直在看后设置主题挂钩

 function set_white_bg() {
 set_theme_mod( custom-background, 'ffffff');   }
 add_action('after_setup_theme', 'set_white_bg');
我也尝试过这一点,但运气不好

function wpse64373_set_custom_background( $new_colour )
{
$old_colour = get_theme_mod(
     'background_color'
    ,get_theme_support( 'custom-background', 'default-color' )
);

  if ( $old_colour == $new_colour )
    return;

return set_theme_mod( 'background_color', $new_colour );
}

function wpse64373_update_custom_background()
{ wpse64373_set_custom_background( 'ffffff' ); }
 add_action( 'switch_theme', 'wpse64373_update_custom_background' );

我做错了什么?

尝试将其添加到子主题的function.php中

add_action('after_setup_theme','child_default_background_color');
function child_default_background_color() {
    $theme_options = get_option( 'twentytwelve_theme_options');
    if ( 'dark' == $theme_options['color_scheme'] )
        $default_background_color = 'ffffff';
    else
        $default_background_color = '333333';

    add_theme_support( 'custom-background', array(
        // set default background color in child theme
        'default-color' => $default_background_color
    ) );
}

谢谢,但是不行。背景颜色与以前相同。