duanjiati1755 2013-03-22 07:11
浏览 24

在主题加载上设置WP custombackground颜色

I'm trying to get my Wordpress twentytwelve child theme to make sure that when the theme is activated the background is white. I can't just add the CSS to the wp_head because then the user can't set a custom background.

I've been looking at the after_setup_theme hook

 function set_white_bg() {
 set_theme_mod( custom-background, 'ffffff');   }
 add_action('after_setup_theme', 'set_white_bg');

I've also tried this - again without luck

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

What am I doing wrong here?

  • 写回答

1条回答 默认 最新

  • douxunwei7083 2013-03-22 07:28
    关注

    Try to add this in your child theme's 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
        ) );
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了