### [wordpress插件文件目录在哪](https://www.prosaas.cn/article/5778) **Published:** 2019-07-15T05:37:53 **Author:** 5201314 **Excerpt:** wordpress的插件目录在wp-content/plugins/下,一个插件一个目录,安装插件时可以把解压… **![](//zhiqipro.oss-cn-beijing.aliyuncs.com/2023/12/20231212124324343.jpg)** **wordpress的插件目录在wp-content/plugins/下,一个插件一个目录,安装插件时可以把解压的插件上传到这个目录下或者在wordpress后台安装插件。** **插件路径相关函数:** plugins\_url() 获取当前插件的目录的 URI,例如一个插件位于/wp-content/plugins/myplugin下,该目录下放有插件的主文件名为myplugin.php,在myplugin.php中执行下面的代码,结果如下 echo plugins\_url(); //输出:http://www.seo628.com/wp-content/plugins echo plugins\_url('',\_\_FILE\_\_); //输出:http://www.seo628.com/wp-content/plugins/myplugin echo plugins\_url('js/myscript.js',\_\_FILE\_\_); //输出:http://www.seo628.com/wp-content/plugins/myplugin/js/myscript.js plugin\_dir\_url() 返回当前插件的目录 URI,例如 echo plugin\_dir\_url(\_\_FILE\_\_ ); //输出:http://www.seo628.com/wp-content/plugins/myplugin/ 注意结尾有反斜杠。 plugin\_dir\_path() 返回当前插件目录的服务器绝对路径,例如 echo plugin\_dir\_path(\_\_FILE\_\_ ); //输出:/home/user/public\_html/wp-content/plugins/myplugin/ 可以用来引用文件,例如 plugin\_basename() 返回调用该函数的插件文件名称(包含插件路径) 例如在插件myplugin下的myplugin.php文件中调用该函数,结果如下 echo plugin\_basename(\_\_FILE\_\_); //输出:myplugin/myplugin.php 如果在myplugin/include/test.php文件中调用(test.php通过include引用到myplugin.php中),结果如下 echo plugin\_basename(\_\_FILE\_\_); //输出:myplugin/include/test.php Url 路径相关常量 WordPress 中还有一组用define定义的常量代表路径。 WP\_CONTENT\_DIR wp-content 目录的服务器绝对路径,例如 /home/user/public\_html/wp-content WP\_CONTENT\_URL wp-content 目录的 URI 地址,例如 http://www.seo628.com/wp-content WP\_PLUGIN\_DIR 插件目录的服务器绝对路径,例如 /home/user/public\_html/wp-content/plugins WP\_PLUGIN\_URL 插件目录的 URI 地址,例如 http://www.seo628.com/wp-content/plugins 更多wordpress相关技术文章,请访问wordpress教程栏目进行学习! 以上就是wordpress插件文件目录在哪的详细内容,更多请关注知企PROSAAS其它相关文章! **Tags:** define, include, php, WordPress, 常量 **Categories:** WordPress ---