admin_print_footer_scripts-(hook_suffix)
Fires when scripts are printed in the footer of a particular admin page.
This event is used to add JavaScript code or enqueue additional scripts immediately before the closing </body> tag in the admin area, but only on the page matching hook_suffix.
It is useful when specific JavaScript must be added to one admin page rather than every page.
Use admin_print_scripts-(hook_suffix) to do the same in the document's <head> section.
Usage
add_action( 'admin_print_footer_scripts-(hook_suffix)', 'wp_kama_admin_print_footer_scripts_hook_suffix_action' );
/**
* Function for `admin_print_footer_scripts-(hook_suffix)` action-hook.
*
* @return void
*/
function wp_kama_admin_print_footer_scripts_hook_suffix_action(){
// action...
}
- $hook_suffix(string)
Unique identifier of the current admin page. Used in the hook name.
Depending on the page type,
$hook_suffixmay be the value of one of these global variables:$hook_suffix = $page_hook; // Result of add_menu_page() or add_submenu_page(). // Or: $hook_suffix = $plugin_page; // plugin_basename( $_GET['page'] ). // Or: $hook_suffix = $pagenow; // PHP filename.
See wp-admin/admin.php.
Possible values of the dynamic
$hook_suffixparameter:For $pagenow
index.php— main Dashboard page.edit.php— posts list.post.php— edit a post.post-new.php— create a new post.edit-tags.php— manage tags and categories.upload.php— Media Library.media-new.php— upload a new media file.edit-comments.php— comments.themes.php— themes.customize.php— Customizer.widgets.php— widgets.nav-menus.php— navigation menus.plugins.php— plugins list.plugin-install.php— install plugins.users.php— users list.user-new.php— add a new user.profile.php— current user profile.edit.php— pages list.edit.php— custom post type list.options-general.php— General Settings.options-writing.php— Writing Settings.options-reading.php— Reading Settings.options-discussion.php— Discussion Settings.options-media.php— Media Settings.options-permalink.php— Permalink Settings.tools.php— Tools.import.php— Import.export.php— Export.admin.php— plugin and custom pages.
For $page_hook
A unique$page_hookis created for custom pages added with add_menu_page() or add_submenu_page(). It is returned by the registration function and looks like:toplevel_page_mypluginmyplugin_page_settings.
Examples
#1 Add a script to a plugin settings page
Insert a script in the footer of a settings page whose hook_suffix is settings_page_myplugin.
add_action( 'admin_print_footer_scripts-settings_page_myplugin', function() {
?>
<script>
console.log('The script was loaded on the plugin settings page');
</script>
<?php
} );Changelog
| Since 4.6.0 | Introduced. |
Where the hook is called
do_action( "admin_print_footer_scripts-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
do_action( "admin_print_footer_scripts-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores