Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/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 ); ?>


(string) (required) A full file path (e.g. __FILE__).
Default: None

Return Values

The absolute path of the directory that contains the file, with trailing slash.


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;

Change Log

Since: 2.8

Source File

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()