Using WordPress ‘register_admin_color_schemes()’ PHP function

The register_admin_color_schemes WordPress PHP function registers the default admin color schemes.

Usage

To use the function, simply add it to your functions.php file:

add_action('admin_init', 'register_admin_color_schemes');

Parameters

  • None

More information

See WordPress Developer Resources: register_admin_color_schemes

Examples

Registering the default admin color schemes

This example registers the default admin color schemes when the admin area is initialized.

function my_register_admin_color_schemes() {
    register_admin_color_schemes();
}
add_action('admin_init', 'my_register_admin_color_schemes');

Adding a custom admin color scheme

This example registers a new custom color scheme called ‘My Custom Scheme’ alongside the default color schemes.

function my_register_custom_admin_color_scheme() {
    wp_admin_css_color(
        'my-custom-scheme', // Unique color scheme identifier
        __('My Custom Scheme'), // Color scheme name
        get_template_directory_uri() . '/my-custom-scheme.css', // Path to the CSS file
    );
    register_admin_color_schemes();
}
add_action('admin_init', 'my_register_custom_admin_color_scheme');

Removing a default color scheme

This example unregisters the ‘Fresh’ color scheme from the list of available admin color schemes.

function my_remove_fresh_color_scheme() {
    unregister_admin_color_scheme('fresh');
}
add_action('admin_init', 'my_remove_fresh_color_scheme');

Removing all default color schemes

This example unregisters all default color schemes, leaving only custom color schemes available.

function my_remove_all_default_color_schemes() {
    unregister_admin_color_scheme('fresh');
    unregister_admin_color_scheme('light');
    unregister_admin_color_scheme('blue');
    unregister_admin_color_scheme('midnight');
    unregister_admin_color_scheme('sunrise');
    unregister_admin_color_scheme('ectoplasm');
    unregister_admin_color_scheme('ocean');
    unregister_admin_color_scheme('coffee');
}
add_action('admin_init', 'my_remove_all_default_color_schemes');

Registering default color schemes only for specific user roles

This example registers the default color schemes only for users with the ‘administrator’ role.

function my_register_admin_color_schemes_for_administrators() {
    if (current_user_can('activate_plugins')) {
        register_admin_color_schemes();
    }
}
add_action('admin_init', 'my_register_admin_color_schemes_for_administrators');