The current_screen WordPress PHP action fires after the current screen has been set.
Usage
add_action('current_screen', 'your_custom_function'); function your_custom_function($current_screen) { // your custom code here return $current_screen; }
Parameters
$current_screen
(WP_Screen): The current WP_Screen object.
More information
See WordPress Developer Resources: current_screen
Examples
Modify admin menu for a custom post type
add_action('current_screen', 'modify_admin_menu'); function modify_admin_menu($current_screen) { if ('your_custom_post_type' == $current_screen->post_type && 'post' == $current_screen->base) { // Modify the admin menu for your custom post type } }
Add custom CSS to a specific admin screen
add_action('current_screen', 'enqueue_custom_css'); function enqueue_custom_css($current_screen) { if ('edit-tags' == $current_screen->base && 'your_taxonomy' == $current_screen->taxonomy) { // Add custom CSS to your taxonomy edit screen wp_enqueue_style('your_custom_css_handle', 'path/to/your/custom.css'); } }
Modify the help tab for a specific screen
add_action('current_screen', 'modify_help_tab'); function modify_help_tab($current_screen) { if ('your_page_id' == $current_screen->id) { // Remove the default help tab and add your custom help tab $current_screen->remove_help_tabs(); $current_screen->add_help_tab(array( 'id' => 'your_custom_help_tab', 'title' => __('Your Custom Help Tab'), 'content' => '<p>Your custom help tab content.</p>', )); } }
Add custom screen option for a specific admin page
add_action('current_screen', 'add_custom_screen_option'); function add_custom_screen_option($current_screen) { if ('your_custom_page_id' == $current_screen->id) { // Add custom screen option add_screen_option('your_custom_option', array( 'label' => __('Your Custom Option'), 'default' => 10, 'option' => 'your_custom_option_per_page', )); } }
Redirect users after saving settings on a specific screen
add_action('current_screen', 'redirect_after_saving_settings'); function redirect_after_saving_settings($current_screen) { if ('your_settings_page_id' == $current_screen->id && isset($_GET['settings-updated'])) { // Redirect users to another page after saving settings wp_redirect(admin_url('admin.php?page=your_redirect_page_id')); exit; } }