WordPress函数 plugins_url 专为获取插件目录下文件的路径而设计。
函数原型:
plugins_url( string $path = '', string $plugin = '' ): string
如果未提供参数,则默认为插件目录URL。
此函数检索plugins或mu plugins目录的绝对URL(不带斜杠),或者在使用$path参数时,检索该目录下的特定文件。您可以将$path参数指定为相对于插件或mu插件目录的硬编码路径,或者方便地传递__FILE__作为第二个参数,使$path相对于当前PHP脚本文件的父目录。
使用举例:
echo '<img src="' . esc_url( plugins_url( 'images/wordpress.png', dirname(__FILE__) ) ) . '" > ';
结果:
<img src="https://www.zhuige.com/wp-content/plugins/my-plugin/images/wordpress.png" >
-
WordPress函数:load_child_theme_textdomain 加载子主题翻译字符串WordPress函数:load_child_theme_textdomain 加载子主题翻译字符串
-
WordPress函数:国际化 __() 获取翻译的字符串WordPress函数:国际化 __() 获取翻译的字符串
-
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 中注册字符串
暂无评论,抢个沙发...