首页 > WordPress学习 > WordPress主题路径相关函数讲解 子主题路径函数调用方法

WordPress主题路径相关函数讲解 子主题路径函数调用方法

时间:2022年11月10日 分类:WordPress学习 浏览量:362

这一篇针对WordPress主题的函数,对于开发WordPress主题的开发者很有帮助;相关函数也可以在WordPress官方文档找到相应的更详细的用法。

以本站 https://news.yynnw.com/ 为例子:

get_theme_root_uri()

获取存放主题的目录URI

echo get_theme_root_uri(); //输出:https://news.yynnw.com/wp-content/themes

get_theme_root()

获取存放主题的目录的服务器绝对路径

echo get_theme_root(); //输出:<tt>/home/.../wp-content/themes</tt>

get_theme_roots()

获取主题目录的目录名称,如果你的主题目录是/wp-content/themes,则

echo get_theme_roots(); //输出:/themes

get_stylesheet_directory()

获取当前启用的主题目录的服务器绝对路径,例如

/home/.../wp-content/themes/twentytwentyone

可以用来include文件,例如

<?php include( get_stylesheet_directory() . '/templates/index.php'); ?>

get_stylesheet_directory_uri()

获取当前启用的主题目录的URI,例如

echo get_stylesheet_directory_uri(); //输出:https://news.yynnw.com/wp-content/themes/twentytwentyone

可以使用在需要主题目录URI的场合,例如图片

<img src="<?php echo get_stylesheet_directory_uri() ?>/images/logo.png" alt="" title="" width="" height="" />

get_template_directory_uri()

如果当前启用的主题是一个child theme,该函数返回parent theme的主题目录URI,用法与get_stylesheet_directory_uri()类似。

get_template_directory()

如果当前启用的主题是一个child theme,该函数返回parent theme的主题目录的服务器绝对路径,用法与get_stylesheet_directory()类似。

get_template()

获取当前启用主题的主题目录名称,例如现在启用的主题为twentytwentyone,则

echo get_stylesheet(); //输出:twentytwentyone

get_stylesheet()

获取当前启用主题的主题目录名称,与get_template()的区别是,如果用了child theme,则返回child theme的目录名称。

版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权

文章名称:WordPress主题路径相关函数讲解 子主题路径函数调用方法

文章链接:https://news.yynnw.com/113.html

该作品系作者结合个人学习经验及互联网相关知识整合。如若侵权请通过投诉通道提交信息,我们将按照规定及时处理。

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

标签:

最新文章

猜你喜欢