get_template_directory_uri()
将始终返回当前父主题的URI。
为了获得子主题URI,您需要使用get_stylesheet_directory_uri()
。
您可以在文档中找到这些内容,以及获取各种主题目录位置的其他有用功能列表。
如果你喜欢使用一个常量,那么TEMPLATEPATH
类似于调用get_template_directory()
(即父主题),并且STYLESHEETPATH类似于调用get_stylesheet_directory()(即,子主题)。
这些常量由WordPress核心设置wp-includes/default-constants.php
,基本如下所示:
define('TEMPLATEPATH', get_template_directory());
...
define('STYLESHEETPATH', get_stylesheet_directory());
如果没有子主题,那么“模板” 和 “样式表”功能都将返回父主题位置。
注意这些函数和以这些函数结尾的函数之间的区别_uri- 这些将返回绝对服务器路径(例如。/home/example/public_html/wp-content/yourtheme),而_uri函数将返回公共地址(又名URL) – 例如。https://example.com/wp-content/themes/yourtheme。