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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)