i’m working on a child theme for the “news” template.

my problem is that there are some functions in the parent theme that are defined in different php files. these files are called in functions.php with require_once.

i think i understand how to unload functions and define my own functions, but how do i point the require_once call to my new file in the child-theme path?

cheers,

troy

2 Answers
2

The functions.php file in child themes is run before the parent theme’s functions.php. There are a few more details in the codex.

IF the parent theme follows development standards, each of their custom functions should work like this:

if( !function_exists( 'a_parent_theme_function' ) ) {
    function a_parent_theme_function() {
        \\ do stuff
    }
}

Then, you just write your own a_parent_theme_function() and it takes precedence because it’s defined first. However, I’d say a majority of themes are built with little regard toward parent theming and so you can’t override the parent function which is a big big bummer.

If you’re using a framework with its own hooks, you might be able to use remove action like this person did to undo the functionality you don’t want and hook in somewhere else to add in what you want, but that feels wrong. Maybe you could even hook into the same hook with a lower priority, undo the result of the function and redo what you want. Again, though, that’s certainly far from ideal.

This question is similar to this previous question on stackoverflow which doesn’t bode well. PHP doesn’t provide an easy way to overload or override an existing function without something like the aforementioned function_exists() check.

Leave a Reply

Your email address will not be published. Required fields are marked *