Languages: English • 日本語 (Add your language)
Retrieves the absolute URL to the plugins or mu-plugins directory (without the trailing slash) or, when using the $path argument, to a specific file under that directory. You can either specify the $path argument as a hardcoded path relative to the plugins or mu-plugins directory, or conveniently pass __FILE__ as the second argument to make the $path relative to the parent directory of the current PHP script file.
<?php plugins_url( $path, $plugin ); ?>
<?php $url = plugins_url(); ?>
<?php $plugins_url = plugins_url(); ?>
The $plugins_url variable will equal to the absolute URL to the plugins or mu-plugins directory, e.g. "http://www.example.com/wp-content/plugins".
The plugins_url() function is commonly used in a plugin file. Passing the __FILE__ PHP magic constant in the place of $plugin parameter makes the $path relative to the parent directory of that file:
<?php echo '<img src="' . plugins_url( 'images/wordpress.png', __FILE__ ) . '" > '; ?>
The above might ouput this HTML markup: <img src="http://www.example.com/wp-content/plugins/my-plugin/images/wordpress.png">.
If you are using the plugins_url() function in a file that is nested inside a subdirectory of your plugin directory, you should use PHP's dirname() function:
<?php echo '<img src="' . plugins_url( 'images/wordpress.png', dirname(__FILE__) ) . '" > '; ?>
The above might ouput this HTML markup: <img src="http://www.example.com/wp-content/plugins/images/wordpress.png">.
return apply_filters( 'plugins_url', $url, $path, $plugin );
plugins_url() is located in wp-includes/link-template.php
.
Plugin paths: plugins_url(), plugin_dir_url(), plugin_dir_path(), plugin_basename()
WordPress Directories: | ||
---|---|---|
home_url() | Home URL | http://www.example.com |
site_url() | Site directory URL | http://www.example.com or http://www.example.com/wordpress |
admin_url() | Admin directory URL | http://www.example.com/wp-admin |
includes_url() | Includes directory URL | http://www.example.com/wp-includes |
content_url() | Content directory URL | http://www.example.com/wp-content |
plugins_url() | Plugins directory URL | http://www.example.com/wp-content/plugins |
theme_url() | Themes directory URL (#18302) | http://www.example.com/wp-content/themes |
wp_upload_dir() | Upload directory URL (returns an array) | http://www.example.com/wp-content/uploads |