Wordpress get plugin directory

2020-05-15 13:00发布

Is there any function that would return the full path of my plugin in WordPress?

Example is

path/wp-contents/plugins/myplugin

I have tried plugin_dir_path(__FILE__) but returns the current dir.

14条回答
Summer. ? 凉城
2楼-- · 2020-05-15 13:32

Code For Plugin Root Path

$dir = plugin_dir_path( __FILE__ );
// Example: /home/user/var/www/wordpress/wp-content/plugins/my-plugin/

Code for plugin path

echo  WP_PLUGIN_DIR.'/plugin-name';
查看更多
我想做一个坏孩纸
3楼-- · 2020-05-15 13:33

I will suggest following code. if you are accessing this function from any subfolder.

plugins_url( 'images/logo.png' , dirname(__FILE__ ));
查看更多
登录 后发表回答