wppaste
WordPress

WP_Theme::get_file_path( string $file = '' ): string

Since
5.9.0
Source
wp-includes/class-wp-theme.php:1611
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 WP_Theme::get_file_path() runs, in this order:

  1. apply_filters( theme_file_path )filterline 1626 (+15 into the body)

    Filters the path to a file in the theme.

Uses · 3

Used by · 1

Source

	public function get_file_path( $file = '' ) {		$file = ltrim( $file, '/' ); 		$stylesheet_directory = $this->get_stylesheet_directory();		$template_directory   = $this->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;		} 		/** This filter is documented in wp-includes/link-template.php */		return apply_filters( 'theme_file_path', $path, $file );	}

History

Introduced in 5.9.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 6.9.7 tag, from src/wp-includes/class-wp-theme.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.