Adding JS to specific Admin Pages
- October 21, 2015
- Leave a comment
To include JS to a specific page without putting conditions in callback function, you just need to do a little modification to admin_print_script, means that you have to append by setting page name to hookname. Hook will then be written as admin_print_script-setting_page.
If you will include JS with this method, then there will be no need to put extra conditions. It will just load JS for that specific page. Below is the sample code:
$hook = add_options_page( 'WP Slider Settings', 'WP Slider', 'manage_options', 'slider_settings_page', 'slider_settings_page');
add_action( 'admin_print_scripts-' . $hook, 'slider_admin_scripts' );
/* put js code here. */