[wp-hackers] Definitive way of getting path to plugin
Rob Miller
r at robm.me.uk
Fri Nov 23 02:18:31 GMT 2007
John Blackbourn wrote:
> Hi everyone,
>
> A plugin of mine references a CSS file which resides in the plugin
> directory (wp-content/plugins/myplugin/style.css) but the path is
> currently hard-coded as I've found no way to get the directory name of
> the plugin. My current code is:
>
> $css = get_bloginfo( 'wpurl' ) . '/' . PLUGINDIR . '/myplugin/style.css' ;
>
> I'd rather not have the "myplugin/" bit hardcoded. Does anyone know of
> an elegant way of getting the name of the plugin directory? Or even
> the entire path to the plugin?
>
> I've been playing around with dirname(), realpath(), __FILE__ and all
> sorts but to no avail. Thanks in advance if anyone is kind enough to
> help.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
basename(dirname(__FILE__))
...should work, returning "foo" for the file
"wp-content/plugins/foo/foo.php". That only works from within your
plugin directory, of course, but it should sort you out in most instances.
--
Rob Miller
http://robm.me.uk/
More information about the wp-hackers
mailing list