-
作者帖子
-
我遇到的问题是,
get_template_directory_uri
指向父主题site/wp-content/themes/twentythirteen/myGallery/gallery_functions_include.php
但我希望它指向我的孩子主题应该是
site/wp-content/themes/child-twentythirteen/myGallery/gallery_functions_include.php
我正在使用的是
include (TEMPLATEPATH . '/myGallery/gallery_functions_include.php');
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 。
-
作者帖子
- 哎呀,回复话题必需登录。