WP_Theme::get_file_path( string $file = '' ): string
- Since
- 5.9.0
- Source
wp-includes/class-wp-theme.php:1619
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:
- apply_filters( theme_file_path )filterline 1634 (+15 into the body)
Filters the path to a file in the theme.
Uses · 3
- apply_filters()Calls the callback functions that have been added to a filter hook.
- WP_Theme::get_stylesheet_directory()Returns the absolute path to the directory of a theme's "stylesheet" files.
- WP_Theme::get_template_directory()Returns the absolute path to the directory of a theme's "template" files.
Used by · 1
- WP_Theme::is_block_theme()Returns whether this theme is a block-based theme or not.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 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.