wordpress get plugin directory url code example
Example 1: how to get plugin directory path in wordpress
$dir = plugin_dir_path( __DIR__ );
Example 2: how to get plugin directory path in wordpress
if ( is_admin() ) {
include_once( plugin_dir_path( __FILE__ ) . 'includes/admin-functions.php' );
} else {
include_once( plugin_dir_path( __FILE__ ) . 'includes/front-end-functions.php' );
}
Example 3: how to get plugin directory path in wordpress
define( 'MY_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
include( MY_PLUGIN_PATH . 'includes/admin-page.php');
include( MY_PLUGIN_PATH . 'includes/classes.php');
Example 4: how to get plugin directory path in wordpress
function plugin_dir_path( $file ) {
return trailingslashit( dirname( $file ) );
}