Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use admin_color_scheme_picker action in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
June 9, 2023
5 minutes read

Alright, fellow WordPress enthusiasts! Today, let’s dive into the fascinating world of WordPress hooks with a focus on the admin_color_scheme_picker action. This is one of those hooks that come in handy when you need to customize the admin color scheme in WordPress. It’s only triggered when there is more than one admin color scheme available. To make this action work, you need to hook a callback to it, which can be done easily using the add_action function. Let’s look at some examples!

Example 1: Adding a Custom Function to the Hook

Below is a simple example showing how to attach a function to the admin_color_scheme_picker action. This function will execute whenever the action is triggered.

    function weplugins_execute_on_admin_color_scheme_picker_event($user_id){
       // Custom code to be executed
    }
    add_action( "admin_color_scheme_picker", "weplugins_execute_on_admin_color_scheme_picker_event" , 10, 1);
    

Example 2: Using Parameters in the Callback

Here, we’re using the $user_id parameter within our function to apply specific logic based on the user ID. This is how you can leverage parameters passed to the hook.

    function weplugins_execute_on_admin_color_scheme_with_params($user_id){
       // Code utilizing $user_id
    }
    add_action( "admin_color_scheme_picker", "weplugins_execute_on_admin_color_scheme_with_params" , 10, 1);
    

Example 3: Removing a Hook Callback

Sometimes, you might need to detach a function from the hook. You can do this using the remove_action function. Just ensure the function name, priority, and number of arguments match.

    remove_action( "admin_color_scheme_picker", "weplugins_execute_on_admin_color_scheme_picker_event", 10, 1 );
    

If you ever find yourself needing to customize the admin_color_scheme_picker action further and require some expert help, don’t hesitate to Contact Us. Our team at WePlugins is always ready to assist!

Access Premium WordPress Plugins

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.