如何从插件WordPress文件夹获取文件路径

Shw*_*miq -1 wordpress twitter-bootstrap

您好,我想使用函数从插件 WordPress 文件夹中wp_enqueue_style注册文件,而不是在目录文件夹中style.css

例如,当我想style.css从主题目录注册时,我使用下面的代码

wp_enqueue_style ('bootstrap_css', get_template_directory_uri().'/css/bootstrap.min.css');
Run Code Online (Sandbox Code Playgroud)

上面的代码是bootstrap.min.css从下面的目录注册文件

/wamp/www/wordpress/wp-content/themes/my-themefolder/css/bootstrab.min.css
Run Code Online (Sandbox Code Playgroud)

但是当插件文件夹中的文件位于下面时,我如何注册相同的文件

/www/wordpress/wp-content/plugins/my-plugin/css/bootstrap.min.css
Run Code Online (Sandbox Code Playgroud)

我必须使用任何函数而不是get_template_directory_uri()获取插件文件夹吗?

Dan*_*jel 7

plugins_url()

要获取插件目录的绝对 URL,请使用plugins_url( $path, $plugin ).

插件_url()
// http://www.example.com/wp-content/plugins

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

plugins_url( '/css/bootstrap.min.css', __FILE__ )  
// http://www.example.com/wp-content/plugins/plugin/css/bootstrap.min.css

此函数检索不带尾部斜杠的 URL。

plugin_dir_url()

要获取文件目录的绝对 URL,请使用plugin_dir_url( $file ).

plugin_dir_url( __FILE__ )  
// http://www.example.com/wp-content/plugins/plugin/

plugin_dir_url( __FILE__ ) 。css/bootstrap.min.css
// http://www.example.com/wp-content/plugins/plugin/css/bootstrap.min.css

此函数检索带有尾部斜杠的 URL。

trailingslashit()

要确保路径以尾部斜杠结尾,请使用trailingslashit( $string ).