Wordpress get plugin directory

前端 未结 14 869
广开言路
广开言路 2021-01-31 02:09

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

Example is

path/wp-contents/plugins/myplugin

I have tr

14条回答
  •  逝去的感伤
    2021-01-31 02:47

    As noted on the section Common Usage of Plugins Url function reference page, that's what worked for me:

    If you are using the plugins_url() function in a file that is nested inside a subdirectory of your plugin directory, you should use PHP's dirname() function:

    echo plugins_url('', dirname(__FILE__) );
    

    The output for this was:

    http://domain/app/wp-content/plugins/my-plugin
    

    The file that called the function was my functions.php inside includes, so the complete path to my file was:

    http://domain/app/wp-content/plugins/my-plugin/includes/functions.php
    

提交回复
热议问题