plugin_dir_path() WordPress Function

The plugin_dir_path() function helps you get the absolute path to the directory where the current plugin is located. You can use this function to include other files or do other operations with the plugin directory.

plugin_dir_path( string $file ) #

Get the filesystem directory path (with trailing slash) for the plugin __FILE__ passed in.


Parameters

$file

(string)(Required)The filename of the plugin (__FILE__).


Top ↑

Return

(string) the filesystem path of the directory that contains the plugin.


Top ↑

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.


Top ↑

Source

File: wp-includes/plugin.php

function plugin_dir_path( $file ) {
	return trailingslashit( dirname( $file ) );
}


Top ↑

Changelog

Changelog
VersionDescription
2.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.