Wordpress get plugin directory

前端 未结 14 866
广开言路
广开言路 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:56

    As mentioned by @tsl143 the function plugins_url() is what you want, along with the __FILE__ magic constant. If you call it from a file inside your plugin folder it will refer to that folder.

    Example:

    For the directory:

    echo plugins_url( '' , __FILE__ ); 
    //outputs: http://www.example.com/wp-content/plugins/my-plugin    
    

    For a file or subdirectory in your plugin directory:

    echo plugins_url( 'images/logo.png' , __FILE__ ); 
    //outputs: http://www.example.com/wp-content/plugins/my-plugin/images/logo.png    
    

提交回复
热议问题