WordPress函数:plugin_dir_url 获取插件文件目录的URL
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函数:human_time_diff 几秒几分几小时前WordPress 自带更友好的时间显示处理函数
-
WordPress函数:wp_is_mobile 判断是否是移动设备WordPress 中如何判断是否是移动设备
-
WordPress函数:wp_die 增强版的 PHP die函数wp_die 优雅的处理异常
-
WordPress函数:get_search_form 获取搜索表单如何在 WordPress 主题中添加搜索表单
-
WordPress函数:get_category_link()通过分类ID获取分类链接get_category_link()是一个通过分类ID获取分类链接的WordPress函数。该函数位于 wp-includes/category-template.php
-
WordPress函数:get_post_field 获取文章字段直接获取文章的字段
暂无评论,抢个沙发...