2013-03-22 129 views
0

我試圖讓我的Wordpress的十二個孩子的主題,以確保當主題被激活時背景是白色的。我不能將CSS添加到wp_head,因爲用戶無法設置自定義背景。在主題加載上設置WP custombackground顏色

我一直在尋找的after_setup_theme鉤

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

我在做什麼錯在這裏?

回答

0

嘗試添加這孩子主題的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 
    )); 
} 
+0

謝謝,但它不工作。背景保持與以前相同的顏色。 – MadsRH 2013-03-22 09:12:03