[wp-hackers] Definitive way of getting path to plugin

Christine Davis christine at neato.co.nz
Fri Nov 23 02:14:35 GMT 2007


I almost* did this by using __FILE__;  and finding the part of the path that
matches the plugins base directory,  and then tacking the right side of the
rest of the path on to the end of wpurl + the plugins base directory.

*It needs a little tweaking to work on windows installs, as I currently have
it; what with the slashes in opposite land.  But you get the general jist.

On 11/23/07, John Blackbourn <johnbillion+wp at gmail.com> 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
>


More information about the wp-hackers mailing list