wordpress中get_template_directory和get_template_directory_uri的区别

wordpress中最常用的两个函数:

get_template_directoryget_template_directory_uri.

这两个函数的功能类似, 都是为了获取路径.

get_template_directory是获取当前主题本地根路径,

get_template_directory_uri是获取http请求时的项目根路径.

get_template_directory函数

当我们在主题引入某些php文件时, 就需要使用get_template_directory,

例如当我们引入php第三方包的autoload时, 就使用了该函数.

这个函数最常搭配的是require_once, include, require

get_template_directory_uri函数

当我们需要开放主题的某些文件(CSS, JS)给网络上的用户时,

我们可以使用该方法get_template_directory_uri,

例如在wordpress注册CSS,JS时就使用了该函数.

猜你喜欢

转载自blog.csdn.net/u014657752/article/details/124591935