I'm trying to enqueue a css and js file on a specific admin page. The targeted page is wp-admin/users.php?page=bp-profile-edit. For that I'm trying:
function my_enqueue ( $hook ) {
if ( 'users.php?page=bp-profile-edit' == $hook ) {
wp_enqueue_script( 'my_custom_script', plugin_dir_url( ) . 'myscript.js' );
wp_enqueue_style( 'my_custom_script', plugin_dir_url( ) . 'mystyle.css' );
}
}
add_action( 'admin_enqueue_scripts', 'my_enqueue' );
It works only on users.php, not on the targeted page.
You could use get_query_var or simpler just use the $_GET param.
So:
function my_enqueue ( $hook ) {
if ( 'users.php' == $hook && isset( $_GET['page'] ) && $_GET['page'] == 'bp-profile-edit' ) {
wp_enqueue_script( 'my_custom_script', plugin_dir_url( ) . 'myscript.js' );
wp_enqueue_style( 'my_custom_script', plugin_dir_url( ) . 'mystyle.css' );
}
}
add_action( 'admin_enqueue_scripts', 'my_enqueue' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With