plugins_url()获取插件所在的网址

目录

描述

Retrieves the absolute URL to the plugins or mu-plugins directory (without the trailing slash) or, when using the $path argument, to a specific file under that directory. You can either specify the $path argument as a hardcoded path relative to the plugins or mu-plugins directory, or conveniently pass __FILE__ as the second argument to make the $path relative to the parent directory of the current PHP script file.

plugins_url() 描述

用法

 <?php plugins_url$path$plugin ); ?> 

Default Usage

<?php $url plugins_url(); ?>

plugins_url() 用法

参数

$path

(string) (可选) Path to the plugin file of which URL you want to retrieve, relative to the plugins or mu-plugins directory or to $plugin if specified.

默认值: None

$plugin

(string) (可选) Path under the plugins or mu-plugins directory of which parent directory you want the $path to be relative to.

默认值: None

plugins_url() 参数

返回值

(string

Absolute URL to the plugins or mu-plugins directory (without the trailing slash) or optionally to a file under that directory.

plugins_url() 返回值

注意

  • 使用到 the WP_PLUGIN_URL or, in the case the $plugin path begins with the WPMU_PLUGIN_DIR path, the WPMU_PLUGIN_URL constant internally, to compose the resultant URL. Note that the direct usage of WordPress internal constants is not recommended.
  • 使用到 apply_filters() to apply "plugins_url" 过滤器s on the resultant URL, with the following line of code:
  • The plugins_url() function should not be called in the global context of plugins, but rather in a hook like "init" or "admin_init" to ensure that the "plugins_url" 过滤器s are already hooked at the time the function is called. This is vital for many site configurations to work, and if plugins_url() is called in the global context of a plugin file it cannot be 过滤器ed by other plugins (though mu-plugins are able to 过滤器 it because they run before any other plugins).

plugins_url() 注意

历史

  • 添加于 版本: 2.6.0

plugins_url() 历史

源文件

plugins_url() 函数的代码位于 wp-includes/link-template.php.

plugins_url() 源文件

相关