Codex tools: Log in
Contents |
admin_enqueue_scripts is the first action hooked into the admin scripts actions. This hook doesn't provide any parameters, so it can only be used to callback a specified function.
<?php add_action( 'admin_enqueue_scripts', 'function_name' ); ?>
where "function_name" is the name of the function to be called.
Sometimes you want to load a set of CSS and/or Javascript documents to all admin pages. You can do this from within your plugin or from your themes function file:
function load_custom_wp_admin_style() {
wp_register_style( 'custom_wp_admin_css', get_template_directory_uri() . '/admin-style.css', false, '1.0.0' );
wp_enqueue_style( 'custom_wp_admin_css' );
}
add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );
In this example we are loading a CSS file from the current active "parent" themes directory.
The admin_enqueue_scripts action hook can also be used to target a specific admin page. In this example we are loading a javascript file in the head section of edit.php.
function my_enqueue($hook) {
if( 'edit.php' != $hook )
return;
wp_enqueue_script( 'my_custom_script', plugins_url('/myscript.js', __FILE__) );
}
add_action( 'admin_enqueue_scripts', 'my_enqueue' );
wp_enqueue_scripts - for enqueuing on front pages
login_enqueue_scripts - for enqueuing on the login page
Return to Plugin API/Action Reference