I have a file that can either be included in a plugin, or in a theme. What’s the best way to get the URL of the file’s folder (from within the file)?

Edit:

I’m now using this for now

home_url( "https://wordpress.stackexchange.com/" . str_replace( ABSPATH, "", dirname( __FILE__ ) ) );

Let me know if there’s any problem with this / there’s a better way.

6 Answers
6

See Determining Plugin and Content Directories.

plugins_url( 'filename', __FILE__ );

… returns the full URI to the file in your plugin. For themes you use:

get_stylesheet_directory_uri() . '/path/to/file';

Leave a Reply

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