WordPress函数 plugin_dir_url 专为获取插件文件目录的URL设计。这函数和 plugin_dir_path 是一对。
函数原型:
plugin_dir_url( string $file ): string
函数源码:
function plugin_dir_url( $file ) {
return trailingslashit( plugins_url( '', $file ) );
}
使用举例:
// 当前目录URL:https://www.zhuige.com/wp-content/plugins/my-plugin/includes/
// 输出:https://www.zhuige.com/wp-content/plugins/my-plugin/includes/images/placeholder.png
echo plugin_dir_url( __FILE__ ).'images/placeholder.png';
// 输出:http://example.com/wp-content/plugins/my-plugin/images/placeholder.png
echo plugin_dir_url( __DIR__ ).'images/placeholder.png';
这函数用法很简单,一看例子什么都明白了。如有兴趣还可以参考:《三分钟热度教程:WordPress插件开发之插件目录下文件路径与URL》
-
WordPress函数:国际化 _x() 获取具有gettext上下文的翻译字符串。WordPress函数:国际化 _x() 获取具有gettext上下文的翻译字符串。
-
WordPress函数:国际化 _ex 展示带上下文的翻译字符串WordPress函数:国际化 _ex 展示带上下文的翻译字符串
-
WordPress函数:国际化 _nx 翻译字符串,_n + _xWordPress函数:国际化 _nx 翻译字符串,_n + _x
-
WordPress函数:国际化 _nx_noop 在 pot 中注册字符串WordPress函数:国际化 _nx_noop 在 pot 中注册字符串
-
WordPress函数:translate_nooped_plural 翻译并注册字符串WordPress函数:translate_nooped_plural 翻译并注册字符串
-
WordPress函数:number_format_i18n 数字国际化WordPress函数:number_format_i18n 数字国际化
暂无评论,抢个沙发...