plugins_url(”,__FILE__) != WP_PLUGIN_URL with sym links

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.

Read More

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

Related posts

2 comments

  1. 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.

  2. 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__) ).'/' );
            }
    

Comments are closed.