Wordpress“;get_template_directory()";返回不正确的路径


Wordpress "get_template_directory()" returning incorrect path

我正试图使用get_template_directory()从特定主题加载文件,但路径不正确,并且在尝试从目录调用特定函数时会导致错误。

get_template_directory()返回的是...html/wp-content/themes/mysite.com v2,而不是正确的目录,即...html/wp-content/themes/mysite-v2(带破折号,而不是空格)。

get_template_directory()在哪里定义,如何更改为以引用正确的目录?

我的问题的解决方案是使用Wordpress的update_option函数更新到正确的主题文件夹。

update_option('template', 'mysite-v2');

在调用get_template_directory()之前执行此操作成功地更新了主题文件夹中对get_template_directory()的所有调用,以反映我传入的主题。

顶级域(TLD) (即.com.org.net不能包含短划线(-)。

您的浏览器正试图直接解释域后面的短划线的含义,但没有成功,因此将短划线替换为url编码的字符串。

更新:您可以使用Wordpress的get_template_template_uri(),并将所需文件的位置连接到活动主题的根文件夹中。

查看此函数的API