Gets the URL (with trailing slash) for the plugin __FILE__ passed in
<?php $url = plugin_dir_url( $file ); ?>
/** * Include CSS file for MyPlugin. */ function myplugin_scripts() { wp_register_style( 'foo-styles', plugin_dir_url( __FILE__ ) . 'assets/foo-styles.css' ); wp_enqueue_style( 'foo-styles' ); } add_action( 'wp_enqueue_scripts', 'myplugin_scripts' );
Would echo:
http://example.com/wp-content/plugins/my-plugin/assets/foo-styles.css
Since: 2.8
plugin_dir_url() is located in wp-includes/plugin.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 |