WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/plugin dir url

Description

Gets the URL (with trailing slash) for the plugin __FILE__ passed in

Usage

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

Parameters

$file
(string) (required) The filename of the plugin (__FILE__)
Default: None

Return Values

(string) 
The URL of the directory that contains the plugin, including a trailing slash ("/")

Change Log

Since: 2.8

Source File

plugin_dir_url() is located in wp-includes/plugin.php

Related

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
See also index of Function Reference and index of Template Tags.