plugin_dir_path( string $file )
Get the filesystem directory path (with trailing slash) for the plugin __FILE__ passed in.
Contents
Description Description
Parameters Parameters
- $file
-
(string) (Required) The filename of the plugin (__FILE__).
Return Return
(string) the filesystem path of the directory that contains the plugin.
Source Source
File: wp-includes/plugin.php
function plugin_dir_path( $file ) { return trailingslashit( dirname( $file ) ); }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
2.8.0 | Introduced. |
More Information More Information
It is a wrapper for trailingslashit( dirname( $file ) );.
The “plugin” part of the name is misleading – it can be used for any file, and will not return the directory of a plugin unless you call it within a file in the plugin’s base directory.
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Including all PHP files from a plugin sub folder and avoiding adding a unnecessary global just to determine a path that is already available everywhere just using WP core functions.
If you want the get the path one level up from the current dir, you can do
Get the directory of the current file:
Define path constant
For calling numerous files, it is sometimes convenient to define a constant:
Conditional loading
It is sometimes efficient to conditionally load files, e.g., admin-only (or even by specific admin screen):