I need to get the current plugin directory like [wordpress_install_dir]/wp-content/plugins/plugin_name
(if getcwd() called from the plugin, it returns [wordpress_install_dir], the root of installation)
thanks for help
I need to get the current plugin directory like [wordpress_install_dir]/wp-content/plugins/plugin_name
(if getcwd() called from the plugin, it returns [wordpress_install_dir], the root of installation)
thanks for help
To get the plugin directory you can use the Wordpress function plugin_basename($file)
. So you would use is as follows to extract the folder and filename of the plugin:
$plugin_directory = plugin_basename(__FILE__);
You can combine this with the URL or the server path of the plugin directory. Therefor you can use the constants WP_PLUGIN_URL
to get the plugin directory url or WP_PLUGIN_DIR
to get the server path.
Read more about it in the Wordpress codex.
Looking at your own answer @Bog, I think you want;
$plugin_dir_path = dirname(__FILE__);
Try this:
function PluginUrl() {
//Try to use WP API if possible, introduced in WP 2.6
if (function_exists('plugins_url')) return trailingslashit(plugins_url(basename(dirname(__FILE__))));
//Try to find manually... can't work if wp-content was renamed or is redirected
$path = dirname(__FILE__);
$path = str_replace("\\","/",$path);
$path = trailingslashit(get_bloginfo('wpurl')) . trailingslashit(substr($path,strpos($path,"wp-content/")));
return $path;
}
echo PluginUrl(); will return the current plugin url.