I’m not sure which functions you are referring to. There’s a few ways to accomplish overrides. I think you may be referring to “pluggable” functions. When such functions are defined in a child, because the child’s functions.php loads first, it takes precedence over the same function in the parent.
This is done by wrapping the function declaration in something like this:
if ( ! function_exists('example_function') ) :
function example_function() {
// do stuff
}
endif;
If example_function() is declared first by the child, the above function declaration is skipped over.
In the 2016 theme, the custom logo is in the theme setup:
add_theme_support( 'custom-logo', array(
'height' => 240,
'width' => 240,
'flex-height' => true,
) );
Basically I did my own in the child theme but it wasn’t working, so in my functions.php, I created a new theme setup and then did my own add_theme_support for the custom logo…this time it worked. However, doing this, I lost th eother setup support elements like menu locations etc, so I had to add that to the child theme setup as well and then got it back with my added menu location.
If you named your setup function twentysixteen_setup(), then as mentioned, the entire parent function is skipped over and you must copy over all support items you want to keep. You should not need to do this since without an override the parent function will still execute. The problem with logo support is independent of the remaining support items, so overriding the entire function is not an ideal response.
If you need to re-declare theme support for one item, the thing to do is create your own function with a unique name, then add it to the “after_theme_setup” action with a large priority number to ensure it is called after the parent’s theme. Then your call to add_theme_support() will overwrite whatever the parent did initially regarding this one item.
hmmm done that but when I test a new logo, it shows the parent theme’s default crop size.
I find it odd that there are tons of tutorials on adding support to a theme, but nothing to show how to override parent theme add_support functions.
UPDATE: Got it to work!
In the twentysixteen_setup, the add_theme_support for a custom logo is this:
add_theme_support( 'custom-logo', array(
'height' => 240,
'width' => 240,
'flex-height' => true,
) );
So in my child theme, I did this:
function twentysixteen_cts_logo() {
add_theme_support( 'custom-logo', array(
'width' => 300,
'height' => 60,
'flex-width' => true,
'flex-height' => true,
) );
}
add_action ('after_setup_theme', 'twentysixteen_cts_logo', 11);
-
This reply was modified 9 years, 2 months ago by
mocha365.