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

Function Reference/plugin basename


Gets the path to a plugin file or directory, relative to the plugins directory, without the leading and trailing slashes.


 <?php plugin_basename$file ); ?> 


(string) (required) Absolute path to a plugin file or directory within the plugins directory.
Default: None


Path to a plugin file or directory, relative to the plugins directory (without the leading and trailing slashes).


If your plugin file is located at /home/www/wp-content/plugins/my-plugin/my-plugin.php, and you call:

$x = plugin_basename( __FILE__ );

The $x variable will equal to "my-plugin/my-plugin.php".


  • Uses both the WP_PLUGIN_DIR and WPMU_PLUGIN_DIR constants internally, to test for and strip the plugins directory path from the $file path. Note that the direct usage of WordPress internal constants is not recommended.

Change Log

Source File

plugin_basename() is located in wp-includes/plugin.php.


Plugin paths: plugins_url(), plugin_dir_url(), plugin_dir_path(), plugin_basename()

WordPress Directories:
home_url() Home URL http://www.example.com
site_url() Site directory URL http://www.example.com or http://www.example.com/wordpress
admin_url() Admin directory URL http://www.example.com/wp-admin
includes_url() Includes directory URL http://www.example.com/wp-includes
content_url() Content directory URL http://www.example.com/wp-content
plugins_url() Plugins directory URL http://www.example.com/wp-content/plugins
theme_url() Themes directory URL (#18302) http://www.example.com/wp-content/themes
wp_upload_dir() Upload directory URL (returns an array) http://www.example.com/wp-content/uploads
See also index of Function Reference and index of Template Tags.