get_template_directory_uri()
get_template_directory_uri()
检索主题目录URI。
Retrieve theme directory URI.
返回(Return)
(string)模板目录URI。
源码(Source)
/** * Retrieve theme directory URI. * * @since 1.5.0 * * @return string Template directory URI. */ function get_template_directory_uri() { $template = str_replace( '%2F', '/', rawurlencode( get_template() ) ); $theme_root_uri = get_theme_root_uri( $template ); $template_dir_uri = "$theme_root_uri/$template"; /** * Filter the current theme directory URI. * * @since 1.5.0 * * @param string $template_dir_uri The URI of the current theme directory. * @param string $template Directory name of the current theme. * @param string $theme_root_uri The themes root URI. */ return apply_filters( 'template_directory_uri', $template_dir_uri, $template, $theme_root_uri ); }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
1.5.0 | wp-includes/theme.php:346 | 12 | 4 |
笔记(Notes)
此函数返回根主题的URL。如果使用子主题,并且要将URL返回到当前子主题,请改用get_stylesheet_directory_uri()。
使用get_template_directory_uri()将静态图像与其html中的正确路径链接:
使用get_template_directory_uri()将具有正确路径的脚本排队。
get_template_directory_uri() 为WP2原创文章,链接:https://www.wp2.cn/functions/get_template_directory_uri/