This page redirects to an external site: https://developer.wordpress.org/reference/functions/plugin_dir_path/
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;
}
Since: 2.8
plugin_dir_path() is located in wp-includes/plugin.php
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 plugins_dir_path()).
Plugin paths:
plugins_url(),
plugin_dir_url(),
plugin_dir_path(),
plugin_basename()