1. WordPress Tutorials

Difference Between plugin_dir_url vs plugins_url

9 / 100 SEO Score

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__));

echo PLUGIN_URL

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

Comments to: Difference Between plugin_dir_url vs plugins_url

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