Home >CMS Tutorial >WordPress >In which folder is the wordpress plugin located?

In which folder is the wordpress plugin located?

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-07-18 15:47:343296browse

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(&#39;MYPLUGINNAME_PATH&#39;, plugin_dir_path(__FILE__) );
require MYPLUGINNAME_PATH . &#39;includes/class-metabox.php&#39;;
require MYPLUGINNAME_PATH . &#39;includes/class-widget.php&#39;;
?>

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:where is wordpress themeNext article:where is wordpress theme