You can’t just redeclare the function in the child theme or call add_action
a second time. It doesn’t replace it, it adds a second hook. As a result, you haven’t overriden it, you’ve duplicated the original. Child theme overrides only work for templates.
What’s more, by adding a second definition of wp_bootstrap_starter_custom_header_setup
you’ve declared the function twice, which would generate a PHP fatal error. You can’t have 2 functions with the same name.
So first, we need to rename your function so that there’s valid PHP:
function sams_custom_header_setup() {
Next, add_action
adds an action. It has no concept of replacing an action. If you call add_action
5 times, the function will run 5 times.
So lets add our action for the new setup:
add_action('after_setup_theme', 'sams_custom_header_setup' );
But remember, the original function got added too, so now both will run! So, remove the original:
remove_action( 'after_setup_theme', 'wp_bootstrap_starter_custom_header_setup' );
TLDR:
- You can’t “override” actions.
- But you can remove them and add a new action to replace them.
- Stop making multiple functions with the same name! That’s invalid PHP, it’ll break things
- Child themes let you override templates loaded via WP, not arbitrary PHP files, functions, hooks, etc
Edit:
It seems the function in your parent theme uses apply_filters
, you could just filter the parameters on the wp_bootstrap_starter_custom_header_args
filter and modify the array itself. You don’t need to mess around replacing the function, or calling add_theme_support