Wordpress - Override get_template_directory() in child theme?

Late answer, but in Wordpress 4.7 two new functions were introduced to address this question.

get_theme_file_path() (for absolute file paths) and get_theme_file_uri() (for URLs) work just like get_template_part() in that they will automatically look in the child theme for that file first, then fallback to the parent theme.

In your example, you could rewrite it using 4.7 to look like this:

/**
* Load Custom Post types file.
*/
require get_theme_file_path( 'inc/post-types.php' );

More information here: https://make.wordpress.org/core/2016/09/09/new-functions-hooks-and-behaviour-for-theme-developers-in-wordpress-4-7/


You need to use get_stylesheet_directory_uri() instead of get_template_directory() in your child theme.

From the WordPress codex:

get_template_directory_uri()

In the event that a child theme is being used, the parent theme directory URI will be returned. get_template_directory_uri() should be used for resources that are not intended to be included in/over-ridden by a child theme. Use get_stylesheet_directory_uri() to include resources that are intended to be included in/over-ridden by the child theme.

get_stylesheet_directory_uri()

In the event a child theme is being used, this function will return the child's theme directory URI. Use get_template_directory_uri() to avoid being overridden by a child theme.