Opened 14 years ago
Closed 14 years ago
#21727 closed enhancement (invalid)
add a new action for scripts and style files in the footer
| Reported by: | alexvorn2 | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Administration | Version: | |
| Severity: | normal | Keywords: | needs-patch |
| Cc: | Focuses: |
Description
add_action('admin_print_scripts-' . $page, 'my_plugin_admin_scripts');
This action adds a custom script file to the header only, introduce a new action for the footer too.
http://codex.wordpress.org/Function_Reference/wp_enqueue_script
Change History (4)
#2
@
14 years ago
you should try to test with a wp_enqueue_style() function for the "admin-header-$page" action, and you will see that the style file is shown at the bottom and not in the head.
#3
@
14 years ago
The proper hook for wp_enqueue_style() in the admin header is admin_enqueue_scripts. $hook_suffix is passed as a parameter in this case.
This example includes a custom script in the header of wp-admin/edit.php:
function my_scripts_method( $hook_suffix ) {
if ( 'edit.php' == $hook_suffix )
wp_enqueue_script( 'custom-script', get_template_directory_uri() . '/js/custom_script.js', array( 'jquery' ) );
}
add_action( 'admin_enqueue_scripts', 'my_scripts_method' );
If any of the later actions is used (e.g. admin_head-$hook_suffix), the script is loaded in the footer:
function my_scripts_method() {
wp_enqueue_script( 'custom-script', get_template_directory_uri() . '/js/custom_script.js', array( 'jquery' ) );
}
add_action( 'admin_head-edit.php', 'my_scripts_method' );
This is also briefly mentioned in the Examples section of the Codex page you linked to.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
There is
admin_footer-$hook_suffix, which mirrorsadmin_head-$hook_suffix:http://core.trac.wordpress.org/browser/tags/3.4.1/wp-admin/admin-footer.php#L32
http://core.trac.wordpress.org/browser/tags/3.4.1/wp-admin/admin-header.php#L68