WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to set default background color in Twenty Eleven child theme (5 posts)

  1. stoneskely
    Member
    Posted 1 year ago #

    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.

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    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
    	) );
    }
  3. stoneskely
    Member
    Posted 1 year ago #

    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.

  4. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

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

    only applies to the function immediately following in the code.

  5. stoneskely
    Member
    Posted 1 year ago #

    That's what I figured - thanks for the confirmation and all the help!

Topic Closed

This topic has been closed to new replies.

About this Topic