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' );

Read More

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?

Related posts

Leave a Reply

2 comments

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

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