Using WordPress ‘admin_print_scripts-{$hook_suffix}’ PHP action

The admin_print_scripts-{$hook_suffix} WordPress PHP action fires when scripts are printed for a specific admin page based on $hook_suffix.

Usage

add_action('admin_print_scripts-{$hook_suffix}', 'your_function_name');
function your_function_name() {
    // your custom code here
}

Parameters

  • None

More information

See WordPress Developer Resources: admin_print_scripts-{$hook_suffix}

Examples

Load a custom script for the dashboard only

Enqueue a custom JavaScript file on the WordPress dashboard.

add_action('admin_print_scripts-index.php', 'load_dashboard_script');
function load_dashboard_script() {
    wp_enqueue_script('custom-dashboard-script', get_template_directory_uri() . '/js/dashboard.js', array('jquery'), '1.0', true);
}

Load a custom script on the post edit screen

Enqueue a custom JavaScript file on the post edit screen.

add_action('admin_print_scripts-post.php', 'load_post_edit_script');
function load_post_edit_script() {
    wp_enqueue_script('custom-post-edit-script', get_template_directory_uri() . '/js/post-edit.js', array('jquery'), '1.0', true);
}

Load a custom script on the post new screen

Enqueue a custom JavaScript file on the post new screen.

add_action('admin_print_scripts-post-new.php', 'load_post_new_script');
function load_post_new_script() {
    wp_enqueue_script('custom-post-new-script', get_template_directory_uri() . '/js/post-new.js', array('jquery'), '1.0', true);
}

Load a custom script on the plugin settings page

Enqueue a custom JavaScript file on your plugin’s settings page.

add_action('admin_print_scripts-settings_page_your_plugin', 'load_plugin_settings_script');
function load_plugin_settings_script() {
    wp_enqueue_script('custom-plugin-settings-script', plugin_dir_url(__FILE__) . 'js/plugin-settings.js', array('jquery'), '1.0', true);
}

Load a custom script on the theme options page

Enqueue a custom JavaScript file on your theme’s options page.

add_action('admin_print_scripts-appearance_page_your_theme_options', 'load_theme_options_script');
function load_theme_options_script() {
    wp_enqueue_script('custom-theme-options-script', get_template_directory_uri() . '/js/theme-options.js', array('jquery'), '1.0', true);
}