I need to remove a function from the parent theme and replace it within the child theme.
The function is called print_meta($meta_box). The function is not pluggable and it located in a random file, not the functions.php file.
The function adds options to a metabox that shows in a page or post. I need to add more options but to do this I re-write the function from within the child theme.
I don’t think I can use remove_filter() as the function is not hooked.
I tried this: print_meta($meta_box)
function remove_parent_theme_functions( $meta_box ) {
remove_filter( 'init', 'print_meta' );
}
add_action( 'after_setup_theme', 'remove_parent_theme_functions' );
but I do not know what tag to use. I have tried all kinds.
Since the function is vital to setting up the metabox option, I assume that if I successfully removed the function when I use metabox I should get an error or the options should not appear.
So far I appear do matter what tag I use.
Is this even possible?
If your description is correct and …
wrapped in a
if (!function_exists())
condition and… then you can’t remove it or replace it except by editing the parent theme file where the function is defined, and then, yes, unless you replace that function with an altered but compatible version with the same name you will get errors. And edits to the parent will be overwritten when the parent is updated.
So I found a way to do it. Its not so much an answer but something you can try.
Since I could not remove the function I was targeting. I traced the function back to where it is was being called, and then to where that function was called…which happend to have an add_action.
So I filtered out that action. Which in turn filtered out the function that lead to my targeted function.
Now all three functions are filtered out. So I Added then back by giving each a new function name and once i got to my targeted function I made the necessary changes. Now form the add_action I have three new named functions and the changes I needed.
It worked it just took some careful copying.