WP_Theme_JSON_Resolver::get_file_path_from_theme() WordPress Method

The WP_Theme_JSON_Resolver::get_file_path_from_theme() method is used to get the path to a file from the current theme. This is useful for loading files that are not part of the theme's core functionality, such as language files or template files.

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

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


Description

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


Top ↑

Parameters

$file_name

(string)(Required)Name of the file.

$template

(bool)(Optional) Use template theme directory.

Default value: false


Top ↑

Return

(string) The whole file path or empty if the file doesn't exist.


Top ↑

Source

File: wp-includes/class-wp-theme-json-resolver.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 : '';
	}


Top ↑

Changelog

Changelog
VersionDescription
5.9.0Adapted to work with child themes, added the $template argument.
5.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.