Using WordPress ‘is_user_admin()’ PHP function

The is_user_admin() WordPress PHP function determines if the current request is for a user admin screen.

Usage

if (is_user_admin()) {
    // Your custom code here
}

Parameters

  • None

More information

See WordPress Developer Resources: is_user_admin()

Examples

Display a message for user admin screens

This example checks if the current request is for a user admin screen and displays a message if true.

if (is_user_admin()) {
    echo 'Welcome to the user admin screen!';
}

Apply custom CSS to user admin screens

This example adds custom CSS to the <head> section of user admin screens.

function my_custom_user_admin_css() {
    if (is_user_admin()) {
        echo '<style>.custom-class { color: red; }</style>';
    }
}
add_action('admin_head', 'my_custom_user_admin_css');

Restrict access to user admin screens for non-administrators

This example checks if the current user is an administrator and redirects non-administrators to the home page when attempting to access user admin screens.

function restrict_user_admin_access() {
    if (is_user_admin() && !current_user_can('manage_options')) {
        wp_redirect(home_url());
        exit;
    }
}
add_action('admin_init', 'restrict_user_admin_access');

Add custom JavaScript to user admin screens

This example adds custom JavaScript to the <footer> section of user admin screens.

function my_custom_user_admin_js() {
    if (is_user_admin()) {
        echo '<script>console.log("Hello, user admin!");</script>';
    }
}
add_action('admin_footer', 'my_custom_user_admin_js');

Show an admin notice on user admin screens

This example displays an admin notice on user admin screens.

function my_user_admin_notice() {
    if (is_user_admin()) {
        echo '<div class="notice notice-success is-dismissible"><p>Your custom message here.</p></div>';
    }
}
add_action('admin_notices', 'my_user_admin_notice');