get_theme_file_path()WP 4.7.0

Gets the path to the specified theme file. Work with child themes.

The function tries to find the specified file in the child theme first. If child theme has no file it gets the path to the file from the main (parent) theme.

This function must be used everywhere while creating a theme in order to any file path of the theme support child theme...

Using this function, you do not need to write special child theme support checks with using get_template_directory_uri() and get_template_directory() functions.

Use get_theme_file_uri() when you need to get the URL of a file rather than it's path.

1 time — 0.000051 sec (very fast) | 50000 times — 0.55 sec (very fast) | PHP 7.1.2, WP 4.7.3
Hooks from the function


String. The path of the file.


$filepath = get_theme_file_path( $file );

File name to search for in the theme directory. For example file.php. You can specify the relative file path inc/file.php or so /inc/file.php.

If you leave empty string, function returns the path to the active theme. See. get_stylesheet_directory().

Default: ''



#1 Demo

echo get_theme_file_path( 'myfile.php' );

The result will be the path to one of the files:


#2 Attach a theme file and consider that a child theme can be used

We can use this function to allow child theme to overwrite a file of the parent theme.

require_once( get_theme_file_path( 'myfile.php' ) );

As a result, the function will check if there is a file myfile.php in the child theme, if it does not exist, it will be connected from the parent (main) theme.


#3 Include file from inc theme directory

include get_theme_file_path( '/inc/template.php' );


Since 4.7.0 Introduced.

get_theme_file_path() code WP 6.4.3

function get_theme_file_path( $file = '' ) {
	$file = ltrim( $file, '/' );

	$stylesheet_directory = get_stylesheet_directory();
	$template_directory   = get_template_directory();

	if ( empty( $file ) ) {
		$path = $stylesheet_directory;
	} elseif ( $stylesheet_directory !== $template_directory && file_exists( $stylesheet_directory . '/' . $file ) ) {
		$path = $stylesheet_directory . '/' . $file;
	} else {
		$path = $template_directory . '/' . $file;

	 * Filters the path to a file in the theme.
	 * @since 4.7.0
	 * @param string $path The file path.
	 * @param string $file The requested file to search for.
	return apply_filters( 'theme_file_path', $path, $file );