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"


修改时间 2023-11-14

声明:本站所有文章和图片,如无特殊说明,均为原创发布,转载请注明出处。
随机推荐
CRSF 跨站脚本攻击已死,使用 Same-Site Cookies 来防范 CSRF
Content Security Policy(CSP)简介
MySQL 批量修改时间
选择排序
WP_Query 函数参数
JavaScript EventSource 服务器发送事件 Server-Sent Events(SSE)
Node.js readline 模块
WordPress关闭自动草稿