How can I get the current plugin directory in WordPress? How can I get the current plugin directory in WordPress? wordpress wordpress

How can I get the current plugin directory in WordPress?


Use the WordPress core function that's designed specifically for that purpose:

<?php plugin_dir_path( __FILE__ ); ?>

See the Codex documentation here.

You also have

<?php plugin_dir_url( __FILE__ ); ?>

if what you're looking for is a URI as opposed to a server path.

See the Codex documentation here.

IMO, it's always best to use the highest-level method that's available in core, and this is it. It makes your code more future-proof.


Looking at the OP's own answer, I think the OP wants;

$plugin_dir_path = dirname(__FILE__);


This will actually get the result you want:

<?php plugin_dir_url(__FILE__); ?>

plugin_dir_url(string $file)