get_parent_theme_file_path()WP 4.7.0

Gets the system path to the parent theme (not the child theme). Does not contain a slash at the end.

If the parameter $file (file name) is specified, it will get the path to this file in the parent theme. Does not check its existence.

This is a wrapper for the function get_template_directory(), which allows specifying the path to a file within the theme, and will also trigger the hook parent_theme_file_path, which can be useful for public themes.

Use get_theme_file_path() when you need to consider the child theme.

Use get_theme_file_uri() when you need to get the URL and consider the child theme.

1 time — 0.002969 sec (very slow) | 50000 times — 2.55 sec (fast) | PHP 7.1.5, WP 4.9.4
Hooks from the function

Returns

String. Path to the file or path to the folder with the parent theme.

Usage

get_parent_theme_file_path( $file = '' );
$file(string)
Path to the file, relative to the parent theme folder. Optional.
Default: ''

Examples

1

#1 Get the path to the folder of the current theme

The result in this example is exactly the same as with get_template_directory().

echo get_parent_theme_file_path();
//> /home/example.com/public_html/wp-content/themes/theme_name
0

#2 Get the path to the file of the current theme

echo get_parent_theme_file_path( '/js/custom.js' );
//> /home/example.com/public_html/wp-content/themes/theme_name/js/custom.js

Changelog

Since 4.7.0 Introduced.

get_parent_theme_file_path() code WP 6.9

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

	if ( empty( $file ) ) {
		$path = get_template_directory();
	} else {
		$path = get_template_directory() . '/' . $file;
	}

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