plugin_dir_url( string $file ): string
Get the URL directory path (with trailing slash) for the plugin __FILE__ passed in.
Parameters
-
$file
string Required -
The filename of the plugin (__FILE__).
Return
string the URL path of the directory that contains the plugin.
Source
File: wp-includes/plugin.php
.
View all references
function plugin_dir_url( $file ) {
return trailingslashit( plugins_url( '', $file ) );
}
Changelog
Version | Description |
---|---|
2.8.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
Let’s say current URL is: http://example.com/wp-content/plugins/my-plugin/includes/
will output: http://example.com/wp-content/plugins/my-plugin/includes/images/placeholder.png
will output: http://example.com/wp-content/plugins/my-plugin/images/placeholder.png
Top ↑
Feedback
Let’s say current URL is: http://example.com/wp-content/plugins/my-plugin/includes/pages/
echo plugin_dir_url( __FILE__ ).'images/placeholder.png';
will output http://example.com/wp-content/plugins/my-plugin/includes/pages/images/placeholder.pngecho plugin_dir_url( __DIR__ ).'images/placeholder.png';
will output http://example.com/wp-content/plugins/my-plugin/includes/images/placeholder.png Which is still not the plugin directory, but only one directory above. I’m still searching for a logical function that returns the root of our plugins. — By Gardian —Basic Example
Would echo:
plugin_dir_url( __FILE__ ) == http://your-url.com/wp-content/plugins/your-plugin/
Top ↑
Feedback
plugin_dir_url vs plugin_dir_path difference
Use it to include your assets (images, css, js etc).
Use it to include php files. — By Mehbub Rashid —