Sorry for the stupid question: I'm trying to create a basic plugin and from its main file I want to refer files in two directories that are in the same directory as the main plugin.

I tried to reference them this way: plugin_dir_path( __FILE__ ).'js/my.js' or plugin_dir_path( __FILE__ ).'imgs/myImg.jpg'

but it crearly creates a path that doesn't work for me.

Anything works fine if I hardcode the absolute path, so this is working fine: http://mydomain/blog/wp-content/plugins/hello-dolly-2/js/view.js?ver=4.8). No luck with relative paths too.

What's the best way to avoid hardcoding my paths? :-)

1 Answer 1


You want to use plugin_dir_url():

$url = plugin_dir_url( __FILE__ ) . 'js/my.js';

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.