在美化、修改主题的时候需要引用一些JS或者其他东西,需要填写路径,一般是填写网址,比如:http://xxx/js/xx.js,但是这样的话如果换域名或者移动主题文件这些引用就会404需要再修改,很不专业,如果用函数来获取URL就不一样了,可以保证你不管是换域名还是移动主题文件都不会出现引用的JS找不到404的问题….
get_theme_root_uri()
获取存放主题的目录 URI
echo get_theme_root_uri(); //输出: http://www.sey.ink/wp-content/themes
get_theme_root()
获取存放主题的目录的服务器绝对路径
echo get_theme_root(); //输出:/home/user/public_html/wp-content/themes
get_theme_roots()
获取主题目录的目录名称,如果你的主题目录是/wp-content/themes
,则
echo get_theme_roots(); //输出:/themes
get_stylesheet_directory()
获取当前启用的主题目录的服务器绝对路径,例如
/home/user/public_html/wp-content/themes/twentyeleven
可以用来 include 文件,例如
<?php include( get_stylesheet_directory() . ‘/includes/myfile.php’); ?>
get_stylesheet_directory_uri()
获取当前启用的主题目录的 URI,例如
echo get_stylesheet_directory_uri(); //输出:http://www.sey.ink/wp-content/themes/twentyeleven
可以使用在需要主题目录 URI 的场合。
比如说引用小鱼的js,例如
<script src="<?php echo get_stylesheet_directory_uri() ?>/js/fish.js"></script>
get_stylesheet()
获取当前启用主题的主题目录名称,与get_template()
的区别是,如果用了 child theme,则返回 child theme 的目录名称。
说点什么