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:
[php]
plugin_dir_url( __FILE__ );
// Return – http://www.example.com/wp-content/plugins/plugin_name/
[/php]
Example #2:
[php]
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
[/php]
Example #3:
[php]
define(‘PLUGIN_URL’, plugin_dir_url(__FILE__));
echo PLUGIN_URL
// retrun http://www.example.com/wp-content/plugins/plugin_name/
[/php]
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:
[php]
plugins_url( ‘img/bar.jpg’ , __FILE__ );
// Return http://www.example.com/wp-content/plugins/foo/img/bar.jpg
[/php]