在主题加载上设置WP custombackground颜色
问题描述:
我试图让我的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');
我在做什么错在这里?
答
尝试添加这孩子主题的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
));
}
谢谢,但它不工作。背景保持与以前相同的颜色。 – MadsRH 2013-03-22 09:12:03