Home > Article > CMS Tutorial > In which folder is the wordpress plugin located?
plugins_url()
Get the URI of the directory of the current plug-in, for example, a plug-in is located at /wp-content/ Under plugins/myplugin, the main file name of the plug-in in this directory is myplugin.php. Execute the following code in myplugin.php. The result is as follows:
echo plugins_url(); //输出:https://www.53431.com/wp-content/plugins echo plugins_url('',__FILE__); //输出:https://www.53431.com/wp-content/plugins/myplugin echo plugins_url('js/myscript.js',__FILE__); //输出:https://www.53431.com/wp-content/plugins/myplugin/js/myscript.js
plugin_dir_url()
Returns the directory URI of the current plug-in, for example
echo plugin_dir_url(__FILE__ ); //输出:https://www.53431.com/wp-content/plugins/myplugin/
Note the backslash at the end.
Related recommendations: "WordPress Tutorial"
plugin_dir_path()
Returns the server absolute path of the current plug-in directory, for example
echo plugin_dir_path(__FILE__ ); //输出:/home/user/public_html/wp-content/plugins/myplugin/
can be used to reference files, for example
<?php define('MYPLUGINNAME_PATH', plugin_dir_path(__FILE__) ); require MYPLUGINNAME_PATH . 'includes/class-metabox.php'; require MYPLUGINNAME_PATH . 'includes/class-widget.php'; ?>
plugin_basename()
Returns the name of the plug-in file that calls this function (including the plug-in Path)
For example, if you call this function in the myplugin.php file under the plug-in myplugin, the result is as follows
echo plugin_basename(__FILE__); //输出:myplugin/myplugin.php
If you call it in the myplugin/include/test.php file (test.php passes include Referenced to myplugin.php), the results are as follows
echo plugin_basename(__FILE__); //输出:myplugin/include/test.php
The above is the detailed content of In which folder is the wordpress plugin located?. For more information, please follow other related articles on the PHP Chinese website!