
Adding JS to specific Admin Pages
- October 21, 2015
- Leave a comment
Adding JavaScript code to a specific page in admin requires coding for identifying the current page and then comparing it with a condition to include code. However, there is a method available to include JS code for a specific page by hooking that particular page.
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:
1 2 3 4 5 6 |
$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' ); function slider_admin_scripts(){ /* put js code here. */ } |
User Comments