函数原型:
get_theme_file_uri( string $file = '' ): string
获取主题下静态文件路径。
在 WordPress 模板文件中,曾看到过各种定位静态文件路径的方法。其实 WordPress 已经提供了封装好的方法。
在模板目录之前的样式表目录中进行搜索,这样从父主题继承的主题就可以覆盖一个文件。
函数源码:
function get_theme_file_uri( $file = '' ) {
$file = ltrim( $file, '/' );
if ( empty( $file ) ) {
$url = get_stylesheet_directory_uri();
} elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
$url = get_stylesheet_directory_uri() . '/' . $file;
} else {
$url = get_template_directory_uri() . '/' . $file;
}
return apply_filters( 'theme_file_uri', $url, $file );
}
从函数源码中可以看出,也是使用了 get_stylesheet_directory_uri、get_template_directory_uri 拼接路径。经过处理后,可以很好的兼容子主题。
包含钩子:
apply_filters( 'theme_file_uri', string $url, string $file )
使用举例:
wp_enqueue_style ( 'custom-font-awesome', get_theme_file_uri('/css/all.min.css'), array () );
-
WordPress函数:esc_html_x 带上下文的转义翻译WordPress函数:esc_html_x 带上下文的转义翻译
-
WordPress函数:esc_attr__ 转义属性及翻译WordPress函数:esc_attr__ 转义属性及翻译
-
WordPress函数:esc_attr_e 属性转义、翻译、显示WordPress函数:esc_attr_e 属性转义、翻译、显示
-
WordPress函数:esc_attr_x 带上下文的转义属性,翻译显示WordPress函数:esc_attr_x 带上下文的转义属性,翻译显示
-
WP Multilang WordPress翻译插件WP Multilang插件的主要功能是提供多语言支持,使用户能够创建多语言版本的网站,满足不同语言用户的需求。
-
WordPress公司官网主题在众多的WordPress企业官网主题中,追格公司推出了多款关于WordPress企业官网主题作品。我们之前已经分享过一些关于追格的企业官网主题,包括收费和免费版本,这些主题都因其独特的设计和出色的功能而深受用户喜爱。
暂无评论,抢个沙发...