Home >CMS Tutorial >WordPress >Where is the wordpress plug-in file directory?

Where is the wordpress plug-in file directory?

尚
Original
2019-07-15 13:37:5312512browse

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

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/

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/

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, 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

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

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

WP_CONTENT_URL

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

http://www.seo628.com/wp-content

WP_PLUGIN_DIR

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

/home/user/public_html/wp-content/plugins

WP_PLUGIN_URL

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

http://www.seo628.com/wp-content/plugins

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!

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