The load-{$page_hook} WordPress PHP action fires before a specific screen is loaded in the admin area, allowing you to perform actions or modify the behavior of the screen.
Usage
add_action('load-{$page_hook}', 'your_custom_function'); function your_custom_function() { // Your custom code here }
Parameters
- $page_hook (string) – The dynamic part of the action name, which consists of the page type, a separator, and the plugin basename without the file extension.
More information
See WordPress Developer Resources: load-{$page_hook}
Examples
Add custom styles to a plugin settings page
Load custom styles for your plugin’s settings page by enqueuing a stylesheet:
add_action('load-settings_page_yourplugin', 'enqueue_yourplugin_styles'); function enqueue_yourplugin_styles() { wp_enqueue_style('yourplugin-styles', plugins_url('yourplugin/css/yourplugin-styles.css')); }
Add custom scripts to a plugin’s top-level page
Load custom JavaScript for your plugin’s top-level page by enqueuing a script:
add_action('load-toplevel_page_yourplugin', 'enqueue_yourplugin_scripts'); function enqueue_yourplugin_scripts() { wp_enqueue_script('yourplugin-scripts', plugins_url('yourplugin/js/yourplugin-scripts.js'), array('jquery')); }
Perform an action before your custom plugin screen is loaded
Execute a specific function before your custom plugin screen is loaded:
add_action('load-toplevel_page_yourplugin', 'yourplugin_pre_load_action'); function yourplugin_pre_load_action() { // Your custom code here, e.g., check user capabilities }
Modify the behavior of a plugin’s settings page
Change the behavior of a plugin’s settings page by modifying its screen options:
add_action('load-settings_page_yourplugin', 'yourplugin_screen_options'); function yourplugin_screen_options() { // Modify screen options, e.g., change the default per_page value add_screen_option('per_page', array('default' => 25)); }
Add a help tab to a plugin’s top-level page
Add a help tab with documentation to your plugin’s top-level page:
add_action('load-toplevel_page_yourplugin', 'yourplugin_add_help_tab'); function yourplugin_add_help_tab() { $screen = get_current_screen(); $screen->add_help_tab(array( 'id' => 'yourplugin_help', 'title' => __('Your Plugin Help'), 'content' => '<p>' . __('This is the help content for your plugin.') . '</p>', )); }