Solution:
The correct hook is admin_print_scripts
1 to enqueue styles and scripts.
Note that admin_footer
and admin_head
also accept the same screen targeting 'actionname-$hook'
:
add_action( 'admin_print_scripts-widgets.php', 'admin_enqueue_so_19228543' );
function admin_enqueue_so_19228543()
{
wp_enqueue_script(
'my-script',
plugins_url( '/my-script.js', __FILE__ ),
array(), // dependencies
false, // version
true // on footer
);
wp_enqueue_style(
'my-style', plugins_url( '/my-style.css', __FILE__ )
);
}
1 The Codex is saying otherwise, but I was pretty sure this was an official stance. I’m researching and will report back.
update
I cannot find any reference to admin_print_scripts
being the correct hook, although it works and I’ve seen used this way many times. For completeness, this is how admin_enqueue_scripts
works:
add_action( 'admin_enqueue_scripts', 'admin_enqueue_so_19228543' );
function admin_enqueue_so_19228543( $hook )
{
if( 'widgets.php' != $hook )
return;
wp_enqueue_script(
'my-script',
plugins_url( '/my-script.js', __FILE__ ),
array(), // dependencies
false, // version
true // on footer
);
wp_enqueue_style(
'my-style', plugins_url( '/my-style.css', __FILE__ )
);
}