plugins_url

Retrieves a URL within the plugins or mu-plugins directory.

Description

(string) plugins_url( (string) $path = '', (string) $plugin = '' ); 

Defaults to the plugins directory URL if no arguments are supplied.

Returns (string)

Plugins URL link with optional paths appended.

Parameters (2)

0. $path — Optional. (string) => ''
Extra path appended to the end of the URL, including the relative directory if $plugin is supplied. Default empty.
1. $plugin — Optional. (string) => ''
A full path to a file inside a plugin or mu-plugin. The URL will be relative to its directory. Default empty. Typically this is done by passing __FILE__ as the argument.

Usage

  1. if ( !function_exists( 'plugins_url' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // Optional. Extra path appended to the end of the URL, including 
  5. // the relative directory if $plugin is supplied. Default empty. 
  6. $path = ''; 
  7. $plugin = ''; 
  8.  
  9. // NOTICE! Understand what this does before running. 
  10. $result = plugins_url($path, $plugin); 
  11.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/link-template.php  
  1. function plugins_url( $path = '', $plugin = '' ) { 
  2.  
  3. $path = wp_normalize_path( $path ); 
  4. $plugin = wp_normalize_path( $plugin ); 
  5. $mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR ); 
  6.  
  7. if ( !empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir) ) 
  8. $url = WPMU_PLUGIN_URL
  9. else 
  10. $url = WP_PLUGIN_URL
  11.  
  12.  
  13. $url = set_url_scheme( $url ); 
  14.  
  15. if ( !empty($plugin) && is_string($plugin) ) { 
  16. $folder = dirname(plugin_basename($plugin)); 
  17. if ( '.' != $folder ) 
  18. $url .= '/' . ltrim($folder, '/'); 
  19.  
  20. if ( $path && is_string( $path ) ) 
  21. $url .= '/' . ltrim($path, '/'); 
  22.  
  23. /** 
  24. * Filters the URL to the plugins directory. 
  25. * @since 2.8.0 
  26. * @param string $url The complete URL to the plugins directory including scheme and path. 
  27. * @param string $path Path relative to the URL to the plugins directory. Blank string 
  28. * if no path is specified. 
  29. * @param string $plugin The plugin file path to be relative to. Blank string if no plugin 
  30. * is specified. 
  31. */ 
  32. return apply_filters( 'plugins_url', $url, $path, $plugin );