[theme-reviewers] Something we need to check for 3.4 appearance -> background

Otto otto at ottodestruct.com
Mon Jun 11 19:00:59 UTC 2012


Yeah okay, in looking closer at this, I see that you might be confused
by the way add_theme_support works. I grant you that it is not
obvious.

The add_theme_support function can be called more than once for the
same item, with different arguments. The first call for a given
argument wins and overrides later calls. The reason for this is
specifically to allow children to override their parent's settings.

So say a parent does this:

add_action('after_setup_theme','parent_setup');
function parent_setup() {
  add_theme_support( 'custom-background', array(
	'default-color' => '000',
	'default-image' => get_template_directory_uri() . '/images/background.jpg'
  ) );
}


Now, a child will do this:
add_action('after_setup_theme','child_setup');
function child_setup() {
  add_theme_support( 'custom-background', array(
	'default-image' => get_stylesheet_directory_uri() . '/images/newbackground.jpg'
  ) );
}

Now, what happens?

Well, the child functions.php is included first. So it adds its own
action first, but nothing else happens yet.

Next, the parent's functions.php is included and it adds its action too.

After both of these have occurred, the after_setup_theme hook is
triggered, and the functions are executed. Since neither set a
priority, the child_setup runs first because it was added first. It
sets the custom-background with the default-image as
/images/newbackground.jpg (in the child directory, thanks to
get_stylesheet_directory_uri() ).

Then the parent runs. It sets the default-color to 000 and also tries
to set the default-image, but the default-image is already set, so
this argument is ignored by the add_theme_support function.

Thus, the child theme has overridden the default-image of the parent,
but notably it has *not* overridden the default-color. This allows for
granularity in the overrides that the child theme can do with regards
to the theme-support settings.

-Otto


More information about the theme-reviewers mailing list