Reputation: 27
In the parent theme's folder there is a function:
add_action('wp_footer', 'znn_load_js');
function znn_load_js() {
include(get_template_directory() . '/javascript.php');
}
I want to override it and include my own javascript.php file. I already tried
remove_action('wp_footer', 'znn_load_js');
But it's not working. Any suggestions?
Upvotes: 0
Views: 3593
Reputation: 3920
If you just need this code to be deleted from your theme, I would suggest removing it from your functions.php entirely. However if you need this to be preserved for some reason, you can set the priority of both the add_action, and remove_action. By setting a lower priority, the action will be executed earlier. By setting a higher priority, the action will be executed later. Whether it is an add_action or remove_action the principal is the same.
I would suggest reading both of these for more info:
http://codex.wordpress.org/Function_Reference/add_action
http://codex.wordpress.org/Function_Reference/remove_action
1] add_action has a default priority of 10, but you can manually set it with the 3rd parameter like so:
add_action('wp_footer', 'znn_load_js', 10);
function znn_load_js() {
include(get_template_directory() . '/javascript.php');
}
2] So set the priority of remove_action and add_action to the same number, in this case, 10. However you could change them both to any priority you want. Place this action hook in the child theme.
add_action('after_setup_theme', 'remove_parent_functions');
function remove_parent_functions() {
remove_action('wp_footer', 'znn_load_js', 10);
}
Upvotes: 2