wp plugin directory path 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
function enqueue_scripts() {
wp_enqueue_script( 'custom-js', plugin_dir_url( __FILE__ ) . 'js/custom.js', array( 'jquery' ), '', true );
wp_enqueue_style( 'style-css', plugin_dir_url( __FILE__ ) . 'css/style.css' );
}
add_action( 'wp_enqueue_scripts', 'enqueue_scripts');
function admin_enqueue_scripts() {
wp_enqueue_script( 'custom-js', plugin_dir_url( __FILE__ ) . 'js/custom.js', array( 'jquery' ), '', true );
wp_enqueue_style( 'style-css', plugin_dir_url( __FILE__ ) . 'css/style.css' );
}
add_action( 'admin_enqueue_scripts', 'admin_enqueue_scripts');
Example 4: 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 5: how to get plugin directory path in wordpress
function myplugin_scripts() {
wp_register_style( 'foo-styles', plugin_dir_url( __FILE__ ) . 'assets/foo-styles.css' );
wp_enqueue_style( 'foo-styles' );
}
add_action( 'wp_enqueue_scripts', 'myplugin_scripts' );
Answer
http: