[wp-trac] [WordPress Trac] #21727: add a new action for scripts and style files in the footer
WordPress Trac
wp-trac at lists.automattic.com
Wed Aug 29 15:43:20 UTC 2012
#21727: add a new action for scripts and style files in the footer
----------------------------+------------------------------
Reporter: alexvorn2 | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Administration | Version:
Severity: normal | Resolution:
Keywords: needs-patch |
----------------------------+------------------------------
Comment (by SergeyBiryukov):
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.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/21727#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list