How to Force a Specific Admin Color Scheme in WordPress

Home » Snippets » How to Force a Specific Admin Color Scheme in WordPress

Created with:



Creator: WPTurbo Team

Customize with WPTurbo AI

Add Snippet To Project

New Project
Add To Existing Project

WordPress admin panel comes with a default color scheme that might not suit everyone’s taste or design preferences. Thankfully, there’s an easy way to change it to something more appropriate. In this article, we’ll show you how to force an admin color scheme so that it always appears the way you want it to, regardless of user preferences. This can be especially helpful if you’re building a custom WordPress theme or working with clients who require a specific brand color scheme. Let’s dive in!

					function wpturbo_force_admin_color_scheme($user_id) {
    $admin_color = 'midnight'; // specify the desired color here, options: 'fresh', 'light', 'blue', 'coffee', 'ectoplasm', 'midnight'
    update_user_meta($user_id, 'admin_color', $admin_color);
add_action('user_register', 'wpturbo_force_admin_color_scheme');

The code snippet above defines a function called wpturbo_force_admin_color_scheme, which takes a $user_id parameter. This function sets the admin color scheme of the specified user to the one specified in the $admin_color variable.

To use this function, you will need to specify the color scheme you want to use. The available options are fresh, light, blue, coffee, ectoplasm, and midnight. The $admin_color variable in the code block represents the specified color scheme we are setting for the user. In this example, we have set $admin_color to midnight.

Once we have set the desired admin color, we use WordPress’ update_user_meta function to update the admin_color user meta for the $user_id. This effectively changes the color scheme of the user in question.

Finally, we use the add_action function to add a hook to the user_register action. This ensures that the wpturbo_force_admin_color_scheme function is executed every time a new user is registered on the WordPress site, thereby forcing the specified color scheme for all new users.

Keep in mind that the actual function that updates the user meta update_user_meta is quite versatile, enabling you to store any user-specific information that you wish to preserve in the user’s meta data.

Register an account to save your snippets or go Pro to get more features.