I’m using the Unite theme in WordPress with a child theme I have created.
When trying to remove an action the php error indicates that the functions.php file from the child theme is loading before the parent /inc/extras.php which contains the hook I want to override.
Trying to do everything correctly rather than just making the quick and dirty change in the parent theme.
Parent /inc/extras.php loaded from include in parent functions.php;
add_action('woocommerce_before_main_content', 'unite_wrapper_start', 10);
add_action('woocommerce_after_main_content', 'unite_wrapper_end', 10);
function unite_wrapper_start() {
echo '<div id="primary" class="col-md-8">';
}
function unite_wrapper_end() {
echo '</div>';
}
When I add remove to the same file it works;
add_action('woocommerce_before_main_content', 'unite_wrapper_start', 10);
add_action('woocommerce_after_main_content', 'unite_wrapper_end', 10);
function unite_wrapper_start() {
echo '<div id="primary" class="col-md-8">';
}
function unite_wrapper_end() {
echo '</div>';
}
remove_action('woocommerce_before_main_content', 'unite_wrapper_start',10);
however, when I add to the child functions.php file it does not;
remove_action('woocommerce_before_main_content', 'unite_wrapper_start',10);
Child functions.php files is certainly loading and working…
Why would this be?
Not so much another answer as an addition to Stuart’s answer above.
This can be used to remove parent theme customisations (dynamic ‘inc’ files) as in a theme like Bard where the parent functions.php ‘requires’ an ‘inc’ file containing a further function and action (bard_dynamic_css).
1) Parent functions file reads:
2) in child functions file:
3) Then require child dynamic css
REMEMBER: change the original function name (in child ‘dynamic-css.php’) to avoid conflicts e.g. ‘bard_dynamic_css’ TO ‘child_bard_dynamic_css’