Frage

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? :-)

War es hilfreich?

Lösung

You want to use plugin_dir_url():

$url = plugin_dir_url( __FILE__ ) . 'js/my.js';
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit wordpress.stackexchange
scroll top