Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
Could you explain what you're trying to accomplish? Are those functions hooked into certain things? Or does the theme use them inside template files? –  chrisguitarguy Oct 16 '11 at 3:52

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.

share|improve this answer

Just think of the require_once like a method to organize your functions. At the end everything is located in functions.php. In other words you can just replace the functions.php with your desired functions. if you want to load files from your parent theme just do

require_once( get_bloginfo('template_directory').'includes_folder/something.php');

Hope it helps

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.