For one of my many sites, plugins/plugin-name is a sym link pointing to universal-install/wp-content/plugins/plugin-name.

echo WP_PLUGIN_URL displays what I expect.
echo plugins_url(); displays what I expect.
echo plugins_url('',__FILE__) displays what I expect followed immediately by the absolute path to the universal plugins directory.

Is there any way I can fix echo plugins_url('',__FILE__) to return only the expected result?

2 Answers 2


When writing a plugin, I define a few constants including the path to the plugin's root folder, and its "name" as used in some admin hooks:

define('WPSE_102681_PLUGIN_NAME', basename(dirname(__FILE__)) . '/' . basename(__FILE__));

I've found that plugins_url() happily takes that constant, which is useful when referencing files from subfolders of the plugin, like so:

echo plugins_url('images/information.png', WPSE_102681_PLUGIN_NAME);

Maybe it'll fix your problem.

  • That's interesting, but I'd like to avoid changing the actual plugin contents so that they can still be updated. You did, however, give me an idea. The plugin directories are being stored as constants in the plugin files, so if they're already defined in the wp-config file, everything works as planned. I'll accept your answer since it does what I asked.
    – ITS Alaska
    Jun 11, 2013 at 22:55

Create plugin then put this code: 1)get plugin dictionary name 2)get plugin url path

add_action( "plugins_loaded", "plugin_path" ) ;
        function plugin_path(){
            define( 'PLUGIN_DIR_PATH', dirname(__FILE__) );
            define( 'PLUGIN_URL_PATH', WP_PLUGIN_URL.'/'.plugin_basename( dirname(__FILE__) ).'/' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.