Difference Between plugin_dir_url vs plugins_url

Function plugin_dir_url()

This will return URL of the plugin directory with a trailing slash at the end. So this can be easily used to link to the plugin directory.

Example #1:

plugin_dir_url( __FILE__ );
// Return - http://www.example.com/wp-content/plugins/plugin_name/

Example #2:

include plugin_dir_url( __FILE__ ) . 'assets/images/zytheme-logo.png';

// retrun http://www.example.com/wp-content/plugins/plugin_name/assets/images/zytheme-logo.png

Example #3:

define('PLUGIN_URL', plugin_dir_url(__FILE__));


// retrun http://www.example.com/wp-content/plugins/plugin_name/

function plugins_url()

If no arguments are passed this will deliver the same result as the above function, but with or without a trailing slash at the end. This can be configured to link to files within the plugin directory; a useful shortcut.
Example #1:

plugins_url( 'img/bar.jpg' , __FILE__ );

// Return http://www.example.com/wp-content/plugins/foo/img/bar.jpg

Newsletter Updates

Enter your email address below to subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *