这篇文章介绍下wordpress中最常用的两个函数get_template_directory和get_template_directory_uri.

这两个函数的功能类似, 都是为了获取路径. 但get_template_directory是获取当前主题本地根路径, 而get_template_directory_uri是获取http请求时的项目根路径.

get_template_directory函数

当我们在主题引入某些php文件时, 就需要使用get_template_directory, 例如当我们引入php第三方包的autoload时, 就使用了该函数.

20220112082222-2022-01-12-08-22-23

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

get_template_directory_uri函数

当我们需要开放主题的某些文件(CSS, JS)给网络上的用户时, 我们可以使用该方法get_template_directory_uri, 例如在wordpress注册CSS,JS时就使用了该函数.

20220112082815-2022-01-12-08-28-16

参考资料

Get_template_directory vs Get_template_directory_uri – Explained

THE END
推荐文章
  • 如何清理WPS的云存储

  • taro编译小程序后报 touristappid Error:tourist appid

  • 小程序中如何让height:100%起作用

  • Google Adsense启用测试模式

  • nodejs实现调用google翻译接口

  • 移除wordpress网站上传限制

  • 黄帝内经-第25篇-宝命全形篇(1)

  • mysql如何备份和还原数据库

评论 共0条
开启精彩搜索

热门搜索

暂无

历史搜索

用户名/邮箱/手机号
密码
用户名
密码
重复密码
邮箱/手机号
验证码
发送验证码
59秒后可重发
注册
找回密码
邮箱/手机号
验证码
发送验证码
59秒后可重发
新密码
重复密码
请选择支付方式
余额支付

购买将消耗【10

微信支付
微信扫码支付 0 元
[ 04分50秒 ]
请使用微信扫一扫
扫描二维码支付
支付宝支付
支付宝扫码支付 0 元
[ 04分50秒 ]
请使用支付宝扫一扫
扫描二维码支付
已完成支付
未完成支付

请输入验证码

点击验证码可以刷新

你确认吗?

确认

2024年10月1日

0字

0字

2024年10月

0字

新增

0字

新增

0字

0字

新增

0字

0字

新增

0字

0字

新增

0字

0字

新增

0字

0字

新增

0字

新增

0字

0字

0字

新增

0字

0字

0字

0字

新增

0字

0字