Codex

Function Reference/plugins url

Contents

Description

The plugins_url template tag retrieves the url to the plugins directory or to a specific file within that directory. You can hardcode the plugin slug in $path or pass __FILE__ as a second argument to get the correct folder name.

Usage

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

Default Usage

<?php $url plugins_url(); ?>

Parameters

$path
(string) (optional) Path relative to the plugins URL
Default: None
$plugin
(string) (optional) The plugin file that you want to be relative to.
Default: None

Return Values

(string) 
Plugins url link with optional path appended.

With no params : http://www.example.com/wp-content/plugins (without end /)

Example

<?php
echo "<img src="' .plugins_url( 'images/wordpress.png' , __FILE__ ). '" > ';
?>

If you are using this function in a file that is nested inside a subdirectory, you should use PHP's dirname() function:

<?php
echo "<img src="' .plugins_url( 'images/wordpress.png' , dirname(__FILE__) ). '" > ';
?>

Filter

Can be filtered with the 'plugins_url' filter, called at the end of the function with the following line of code:

return apply_filters('plugins_url', $url, $path, $plugin);

Note: This function should not be called in the global context of plugins, but rather in a hook like 'init' or 'admin_init'. It is vital that the 'plugins_url' filter be functional for many site configurations to work, and if plugins_url() is called in the global context of a plugin file it cannot be filtered by other plugins (though mu-plugins are able to filter it because they run before any other plugins).

Notes

  • Uses WP_PLUGIN_URL and WPMU_PLUGIN_URL;

Change Log

Source File

plugins_url() is located in wp-includes/link-template.php.

Related

home_url() Home URL http://www.example.com
site_url() Site directory URL http://www.example.com OR http://www.example.com/wordpress
admin_url() Admin directory URL http://www.example.com/wp-admin
includes_url() Includes directory URL http://www.example.com/wp-includes
content_url() Content directory URL http://www.example.com/wp-content
plugins_url() Plugins directory URL http://www.example.com/wp-content/plugins
wp_upload_dir() Upload base URL in ['baseurl'] entry of returned array http://www.example.com/wp-content/uploads
See also index of Function Reference and index of Template Tags.