wppaste
WordPress

get_theme_file_path( string $file = '' ): string

Since
4.7.0
Source
wp-includes/link-template.php:4710
Retrieves the path of a file in the theme.

Description

Searches in the stylesheet directory before the template directory so themes which inherit from a parent theme can just override one file.

Parameters

$filestringoptional
File to search for in the stylesheet directory.Default: ''

Return

string
The path of the file.

Hooks fired · 1

One hook fires while get_theme_file_path() runs, in this order:

  1. apply_filters( theme_file_path )filterline 4732 (+22 into the body)

    Filters the path to a file in the theme.

Uses · 3

Used by · 5

Source

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

History

Introduced in 4.7.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/link-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.