在get\\u template\\u directory()上使用get\\u parent\\u theme\\u file\\u path()是否有特定原因
对此新功能附带一个过滤器
如果查看get_parent_theme_file_path() 来源,它刚刚回来get_template_directory() 具有额外的功能,例如如果将文件作为get_parent_theme_file_path 它返回文件的路径,并且parent_theme_file_path 可以很好地覆盖的过滤器。
get_parent_theme_file_path 为保持一致性并允许轻松覆盖子主题而引入。我看不出用这个代替get_template_directory.
我写了一个post 在这些函数上,这可能会有所帮助。
Use case:
假设您在主题中包含一个文件,使用
get_template_directory 如下所示。
include(get_template_directory().\'/inc/bk.php\'); /*../themes/bk-theme/inc/bk.php */
 如果你想覆盖
bk.php 在儿童主题中不是
possible如果在新函数中包含相同的文件
include(get_parent_theme_file_path(\'inc/bk.php\')); /*../bk-theme/inc/bk.php */
 您可以使用
parent_theme_file_path 如下所示
add_filter(\'parent_theme_file_path\',\'bk_257597_parent_theme_file\',10,2);
function bk_257597_parent_theme_file($path,$file){
 if(\'inc/bk.php\' == $file) {
  //do something
  $file = \'my-file\';
  $path = \'my-path\'.$file;
 }
 return $path;
}