plugins_url()
function accepts plugin slug or file path to build URL for.
I have following directory structure:
/wp-content/mu-plugins/someplugin/css/file.css
/wp-content/mu-plugins/someplugin/includes/file.php
I need to build URL to file.css
in file.php
. I can’t pass __FILE__
because that will be one level too deep.
plugins_url('css/file.css', __FILE__ )
I can pass __DIR__
to get correct level and it seems to work, but it’s not documented as allowed and I am not sure there isn’t something to bite me later with this.
plugins_url('css/file.css', __DIR__ )
So, is this adequate? Any better way to build URL for these conditions?
__DIR__
is rather new and not always supported. Usedirname( __FILE__ )
.plugins_url()
is using â¦â¦ so yes, it is safe.
Just use
plugins_url( 'subfolder/file.css', dirname( __FILE__ ) )