钩子文档

theme_file_path

💡 云策文档标注

概述

theme_file_path 是一个 WordPress 过滤器钩子,用于修改主题中文件的路径。它允许开发者在获取主题文件路径时进行自定义处理。

关键要点

  • 这是一个过滤器钩子,用于过滤主题文件的路径。
  • 接受两个参数:$path(文件路径)和 $file(请求搜索的文件)。
  • 在 WordPress 4.7.0 版本中引入。

代码示例

return apply_filters( 'theme_file_path', $path, $file );

注意事项

  • 与 get_theme_file_path() 和 WP_Theme::get_file_path() 函数相关,用于检索主题文件路径。
  • 常用于检查主题或其父主题是否包含 theme.json 文件,如 wp_theme_has_theme_json() 函数所示。

📄 原文内容

Filters the path to a file in the theme.

Parameters

$pathstring
The file path.
$filestring
The requested file to search for.

Source

return apply_filters( 'theme_file_path', $path, $file );

Changelog

Version Description
4.7.0 Introduced.