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

In which folder is the wordpress plugin located?

爱喝马黛茶的安东尼
Release: 2019-07-18 15:47:34
Original
3255 people have browsed it

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
Copy after login

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/
Copy after login

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/
Copy after login

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;;
?>
Copy after login

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
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template