How to create custom admin color schemes in WordPress with wp_admin_css_color

The wp_admin_css_color function in WordPress is essentially a way to register a new color scheme for the admin interface. This function is part of the WordPress API and allows developers to customize the appearance of the admin dashboard by introducing new color schemes.

The color scheme can be applied on a per-user basis, meaning that each user can have their own unique color scheme for the admin interface. This can be particularly useful in multi-user environments, where individual users may prefer different color schemes for ease of use or aesthetic reasons.

It is also worth noting that the color scheme can be changed at any time, and the changes will be immediately reflected in the admin interface. This allows for dynamic customization of the admin dashboard, making it possible to change the color scheme based on specific conditions or events.

Parameters Accepted by wp_admin_css_color Function

The wp_admin_css_color function in WordPress accepts several parameters, which are listed and described below:

  • $key (string, required): This is a unique identifier for the theme.
  • $name (string, required): This refers to the theme’s name.
  • $url (string, required): This is the URL for the CSS file that contains the color scheme.
  • $colors (array, optional, default: array()): This is an array of CSS color definition strings. These are used to give users an idea of the theme’s color scheme.
  • $icons (array, optional, default: array()): This is an array of CSS color definitions which are used to color SVG icons. The array includes:
    • base (string): The base color for the SVG icons.
    • focus (string): The color of the SVG icons when they are in focus.
    • current (string): The color of the SVG icon for the current admin menu link.

Return Value of wp_admin_css_color Function

The wp_admin_css_color function does not return any value.

Examples

How to Add a Custom Admin Color Scheme in WordPress

The following code snippet shows how to use the wp_admin_css_color function to add a custom admin color scheme in WordPress.

function custom_admin_color_scheme() {
 $theme_name = 'My Custom Theme';
 $theme_url = get_stylesheet_directory_uri() . '/my-custom-theme.css';
 $theme_colors = array('#202020', '#ffffff', '#dfdfdf', '#464646');
 $theme_icons = array(
 'base' => '#202020',
 'focus' => '#ffffff',
 'current' => '#dfdfdf',
 );

 wp_admin_css_color('my_custom_theme', $theme_name, $theme_url, $theme_colors, $theme_icons);
}

add_action('admin_init', 'custom_admin_color_scheme');

This code defines a new admin color scheme called “My Custom Theme”. The colors and icons for the theme are defined by the $theme_colors and $theme_icons arrays respectively. The CSS file for the theme is located at the URL specified by $theme_url. The new color scheme is registered with WordPress using the wp_admin_css_color function, and is added to the admin interface using the admin_init action hook.

Conclusion

The wp_admin_css_color function in WordPress is a versatile tool that allows developers to register a custom admin color scheme. This function essentially gives developers the power to change the appearance of the WordPress admin panel by adjusting the color palette. Therefore, it can be used to customize the WordPress admin interface to match the branding of a website or to create a unique user experience for site administrators. The wp_admin_css_color function is an integral part of the WordPress API, providing developers with a high level of control over the visual aspect of the admin panel.

Related WordPress Functions