Home > CMS Tutorial > WordPress > body text

Where is the wordpress plug-in file directory?

Release: 2019-07-20 15:41:35
Original
12447 people have browsed it

Where is the wordpress plug-in file directory?

The plugin directory of wordpress is under wp-content/plugins/, one directory for each plugin. When installing the plugin, you can upload the decompressed plugin to this directory or install the plug-in in the WordPress backend.

Plug-in path related functions:

plugins_url()

Get the URI of the current plug-in directory, for example, a plug-in is located Under /wp-content/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();
//输出: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
Copy after login

plugin_dir_url()

Return the directory URI of the current plug-in, such as

echo plugin_dir_url(__FILE__ );
//输出:http://www.seo628.com/wp-content/plugins/myplugin/
Copy after login

Note that there is a backslash at the end.

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, when calling 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 Called in the myplugin/include/test.php file (test.php is referenced to myplugin.php through include), the results are as follows

echo plugin_basename(__FILE__);
//输出:myplugin/include/test.php
Copy after login

Url path related constants

There is also a group of define in WordPress The defined constants represent paths.

WP_CONTENT_DIR

The server absolute path of the wp-content directory, for example

/home/user/public_html/wp-content
Copy after login

WP_CONTENT_URL

The URI address of the wp-content directory, for example

http://www.seo628.com/wp-content
Copy after login

WP_PLUGIN_DIR

The absolute path of the server to the plug-in directory, such as

/home/user/public_html/wp-content/plugins
Copy after login

WP_PLUGIN_URL

The URI address of the plug-in directory, such as

http://www.seo628.com/wp-content/plugins
Copy after login

More wordpress related For technical articles, please visit the wordpress tutorial column to learn!

The above is the detailed content of Where is the wordpress plug-in file directory?. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!