get_theme_file_path( string $file = '' ): string
- Since
- 4.7.0
- Source
wp-includes/link-template.php:4659
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:
- apply_filters( theme_file_path )filterline 4681 (+22 into the body)
Filters the path to a file in the theme.
Uses · 3
- get_stylesheet_directory()Retrieves stylesheet directory path for the active theme.
- get_template_directory()Retrieves template directory path for the active theme.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 5
- Twenty_Twenty_One_Customize::register()Register customizer options.
- Twenty_Twenty_One_Dark_Mode::customizer_controls()Registers customizer options.
- get_block_editor_theme_styles()Creates an array of theme styles to load into the block editor.
- twenty_twenty_one_get_non_latin_css()Get custom CSS.
- twentytwentytwo_register_block_patterns()Registers block patterns and categories.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 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.