WordPress 获取当前主题文件夹的路径

在 WordPress 主题模板制作的时候经常需要获取当前模板的文件夹服务器路径,因为经常忘的原因,所以在这里总结下几种方法,并且区分其之间的差别:

1,bloginfo('template_url');

http://localhost/wordpress/wp-content/themes/mytheme


2,bloginfo('template_directory');

http://localhost/wordpress/wp-content/themes/mytheme


3,echo get_template_directory_uri(); 

http://localhost/wordpress/wp-content/themes/mytheme


4, echo get_stylesheet_directory_uri();

http://localhost/wordpress/wp-content/themes/simplespace_free 


5, echo get_template_directory();

/www/test_com/wordpress/wp-content/themes/simplespace_free


6,echo home_url(); 

http://localhost/wordpress 

是首页地址,比如logo的链接,“面包屑”的“首页”链接等等 


7,echo site_url(); 

http://localhost/wordpress 

返回wordpress安装路径 如获得test.jpg图片文件绝对路径拼接:site_url()."/images/test.jpg"


真诚赞赏,手留余香
赞赏
前端
FFmpeg 修改默认音轨
2022-05-01
PHP
WordPress 支持事务
2022-06-15
ngtwewy
在什么样的花园里面,挖呀挖呀挖
种什么样的种子,开什么样的花
随机推荐
Nginx 的 location 设置
什么是 RESTful API 的幂等性
CSS 媒体特性 prefers-color-scheme
macOS 生成 icns 图标
uni-app 实现暗黑模式/夜间模式/深色模式/暗黑主题(DarkMode)的几种方法
PHP-FPM 对三种子进程的管理模式
JavaScript 检查 Date 是否为 Invalid Date
Linux 下 configure、make 、make test/make check、sudo make install 的作用
MySQL 表名预处理
MySQL DATETIME 时间查询和转换

微信联系我

夜间模式切换
回到顶部