HTTP/2 301
server: nginx
date: Fri, 26 Dec 2025 18:34:52 GMT
content-type: text/html; charset=UTF-8
x-olaf: ⛄
vary: accept, content-type
x-redirect-by: WordPress
location: https://developer.wordpress.org/reference/functions/plugin_dir_url/
x-frame-options: SAMEORIGIN
alt-svc: h3=":443"; ma=86400
x-nc: MISS ord 1
HTTP/2 200
server: nginx
date: Fri, 26 Dec 2025 18:34:53 GMT
content-type: text/html; charset=UTF-8
vary: Accept-Encoding
x-olaf: ⛄
vary: accept, content-type
link:
; rel="https://api.w.org/"
link:
; rel="alternate"; title="JSON"; type="application/json"
link: ; rel=shortlink
x-frame-options: SAMEORIGIN
content-encoding: gzip
alt-svc: h3=":443"; ma=86400
x-nc: MISS ord 1
plugin_dir_url() – Function | Developer.WordPress.org
plugin_dir_url( string $file ): string
Get the URL directory path (with trailing slash) for the plugin __FILE__ passed in.
$filestringrequiredThe filename of the plugin (__FILE__).
string the URL path of the directory that contains the plugin.
| Version | Description |
|---|
| 2.8.0 | Introduced. |
Let’s say current URL is: https://example.com/wp-content/plugins/my-plugin/includes/
will output: https://example.com/wp-content/plugins/my-plugin/includes/images/placeholder.png
will output: https://example.com/wp-content/plugins/my-plugin/images/placeholder.png
echo plugin_dir_url( __FILE__ ).'images/placeholder.png';will output https://example.com/wp-content/plugins/my-plugin/includes/pages/images/placeholder.pngecho plugin_dir_url( __DIR__ ).'images/placeholder.png';will output https://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.Basic Example
Would echo:
plugin_dir_url( __FILE__ ) == https://your-url.com/wp-content/plugins/your-plugin/Use it to include your assets (images, css, js etc).
Use it to include php files.