Title: WP_Theme_JSON_Resolver::get_file_path_from_theme
Published: July 20, 2021
Last modified: April 28, 2025

---

# WP_Theme_JSON_Resolver::get_file_path_from_theme( string $file_name, bool $template = false ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_file_path_from_theme/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_file_path_from_theme/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_file_path_from_theme/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_file_path_from_theme/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_file_path_from_theme/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_file_path_from_theme/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_file_path_from_theme/?output_format=md#wp--skip-link--target)

Builds the path to the given file and checks that it is readable.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_file_path_from_theme/?output_format=md#description)󠁿

If it isn’t, returns an empty string, otherwise returns the whole file path.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_file_path_from_theme/?output_format=md#parameters)󠁿

 `$file_name`stringrequired

Name of the file.

`$template`booloptional

Use template theme directory.

Default:`false`

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_file_path_from_theme/?output_format=md#return)󠁿

 string The whole file path or empty if the file doesn’t exist.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_file_path_from_theme/?output_format=md#source)󠁿

    ```php
    protected static function get_file_path_from_theme( $file_name, $template = false ) {
    	$path      = $template ? get_template_directory() : get_stylesheet_directory();
    	$candidate = $path . '/' . $file_name;

    	return is_readable( $candidate ) ? $candidate : '';
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-theme-json-resolver.php#L727)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-theme-json-resolver.php#L727-L732)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_file_path_from_theme/?output_format=md#related)󠁿

| Uses | Description | 
| [get_template_directory()](https://developer.wordpress.org/reference/functions/get_template_directory/)`wp-includes/theme.php` |

Retrieves template directory path for the active theme.

  | 
| [get_stylesheet_directory()](https://developer.wordpress.org/reference/functions/get_stylesheet_directory/)`wp-includes/theme.php` |

Retrieves stylesheet directory path for the active theme.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_file_path_from_theme/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Adapted to work with child themes, added the `$template` argument. | 
| [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_theme_json_resolver%2Fget_file_path_from_theme%2F)
before being able to contribute a note or feedback.