Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress enqueue scripts on admin subpage

Tags:

php

wordpress

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.

like image 650
Adrian Avatar asked Mar 22 '26 06:03

Adrian


1 Answers

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' );
like image 151
kindisch Avatar answered Mar 24 '26 19:03

kindisch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!