get_parent_theme_file_path()WP 4.7.0

Retrieves the path of a file in the parent 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

Return

String. The path of the file.

Usage

get_parent_theme_file_path( $file );
$file(string)
File to return the path for in the template directory.
Default: ''

Examples

0

#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.1.1

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