Should I ask a theme developer to use locate_template rather than require_once

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?

2 Answers
2

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).

Leave a Comment