Codex tools: Log in
Contents |
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.
<?php plugins_url( $path, $plugin ); ?>
<?php $url = plugins_url(); ?>
With no params : http://www.example.com/wp-content/plugins (without end /)
<?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__) ). '" > '; ?>
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).
plugins_url() is located in wp-includes/link-template.php.
| 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 |