WordPress.org

Support

Support » Themes and Templates » [Resolved] How to set default background color in Twenty Eleven child theme

[Resolved] How to set default background color in Twenty Eleven child theme

  • I am building a child theme based off Twenty Eleven and am trying to figure out how to change the default background color you normally change at Appearance/Background/Display Options/Background Color in the Twenty Eleven theme.

    The default color is #f1f1f1 under Twenty Eleven. I want to change this in my child theme so the default color is something else, like #333333. I am trying to avoid having to manually change the background color every time I activate the child theme or install it on a different WordPress blog.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Michael

    @alchymyth

    Forum Moderator

    try to add this to functions.php of the child theme:

    add_action('after_setup_theme','child_default_background_color');
    function child_default_background_color() {
    	$theme_options = get_option( 'twentyeleven_theme_options');
    	if ( 'dark' == $theme_options['color_scheme'] )
    		$default_background_color = '0f0f0f';
    	else
    		$default_background_color = '333333';
    
    	add_theme_support( 'custom-background', array(
    		// set default background color in child theme
    		'default-color' => $default_background_color
    	) );
    }

    That worked perfectly! Thank you!

    One final question, since my php skills are limited, does the line:
    add_action('after_setup_theme','child_default_background_color');
    only apply to the function immediately following it, or to all code after the line? Currently, I have this code at the end of the functions.php file, but I would like to move it to the top if possible.

    Michael

    @alchymyth

    Forum Moderator

    add_action()
    http://codex.wordpress.org/Function_Reference/add_action

    only applies to the function immediately following in the code.

    That’s what I figured – thanks for the confirmation and all the help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] How to set default background color in Twenty Eleven child theme’ is closed to new replies.
Skip to toolbar