Codex tools: Log in
Gets the filesystem directory path (with trailing slash) for the file passed in.
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.
<?php $path = plugin_dir_path( $file ); ?>
Get the directory of the current file:
$dir = plugin_dir_path( __FILE__ ); // Example: /home/user/var/www/wordpress/wp-content/plugins/my-plugin/
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.
foreach ( glob( plugin_dir_path( __FILE__ )."subfolder/*.php" ) as $file ) include_once $file;
plugin_dir_path() is located in
This can be fairly reliably used to find the local path to the plugins directory by using a string manipulation to remove just the base directory of the plugin (equivalent to the non-existent