get_theme_file_path() - WordPress 函数参考中文文档

返回介绍

get_theme_file_path()

发布于 2017-09-11 字数1837 浏览 920 评论 0

get_theme_file_path( string $file = '' )

Retrieves the path of a file in the theme.


描述

Searches in the stylesheet directory before the template directory so themes which inherit from a parent theme can just override one file.


参数

$file

(string)
(Optional)
File to search for in the stylesheet directory.

Default value: ”


返回值

(string) The path of the file.


源代码

File: wp-includes/link-template.php

function get_theme_file_path( $file = '' ) {
	$file = ltrim( $file, '/' );

	if ( empty( $file ) ) {
		$path = get_stylesheet_directory();
	} elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
		$path = get_stylesheet_directory() . '/' . $file;
	} else {
		$path = get_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 );
}

更新日志

Version 描述
4.7.0 Introduced.

相关函数

Uses

  • wp-includes/link-template.php:
    theme_file_path
  • wp-includes/theme.php:
    get_stylesheet_directory()
  • wp-includes/theme.php:
    get_template_directory()
  • wp-includes/plugin.php:
    apply_filters()

User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!