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 was creating a child theme today and needed to overwrite a php file which was included using this code in the themes functions.php file

require_once( get_template_directory() . '/function-includes/theme-functions.php' );

I tried using require_once( get_stylesheet_directory(). '/function-includes/theme-functions.php' ); in my child themes functions file but it caused an error and didn't load the site at all.

So I ended up using locate_template( '/function-includes/theme-functions.php', true ); in the parent themes functions.php file

Is locate_template a better method for theme developers to use to allow child theme development?

Is there an alternative way for me to use only my child themes functions.php to overwrite that theme-functions.php file?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Generally speaking, Child Themes were originally intended to be able to do two things:

  1. Override parent Theme CSS
  2. Override parent Theme template files

I doubt that the Theme developer intends for the /function-includes/theme-functions.php file to be overridden by a Child Theme. Functional files are usually a core component of the Theme, and allowing a Child Theme to override them wholesale would introduce serious development complexity into the Theme.

Rather than ask for a functional file to be able to be overridden by a Child Theme, I would instead ask the developer to make custom function output filterable, or (where appropriate), to make some custom functions pluggable (by far, I prefer filterable function output to pluggable functions).

share|improve this answer
    
Thanks Chip that makes more sense to ask that they add filters and hooks into the theme. –  Anagio Feb 16 '13 at 13:12

Are you trying to retrieve the theme-functions.php file located in the parent theme directory?

When you want to call a file from the parent theme directory you must use,

get_template_directory()

When you want to call a file from your child theme directory then you use,

get_stylesheet_directory()
share|improve this answer
    
No i'm trying to get the file from my child theme which is why I used get_stylesheet_directory() and it just displayed a white / blank page and nothing loaded at all. –  Anagio Feb 16 '13 at 11:44

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.