do_action( 'admin_enqueue_scripts', string $hook_suffix )
Enqueue scripts for all admin pages.
Contents
Description Description
Parameters Parameters
- $hook_suffix
-
(string) The current admin page.
Source Source
Changelog Changelog
Version | Description |
---|---|
2.8.0 | Introduced. |
More Information More Information
admin_enqueue_scripts
is the proper hook to use when enqueuing scripts and styles that are meant to be used in the administration panel. Despite the name, it is used for enqueuing both scripts and styles.
It provides a single parameter, $hook_suffix
, that informs the current admin page. This should be used to enqueue scripts and styles only in the pages they are going to be used, and avoid adding script and styles to all admin dashboard unnecessarily.
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Selectively enqueue a script in the admin
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.
Figure out your $hook name
If you are unsure what the $hook name of the current admin page of which you want to conditionally load your script is, add this to your page:
Enqueue a custom stylesheet in the admin
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:
Another way to load scripts or css in specific admin page by using this function
In this example, we are loading a javascript and a css file in the head section of nav-menus.php page.
Expand full source codeCollapse full source code
Load css and js only on a particular sub-menu page